mca-device.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /*
  3. * MCA device support functions
  4. *
  5. * These functions support the ongoing device access API.
  6. *
  7. * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
  8. *
  9. **-----------------------------------------------------------------------------
  10. **
  11. ** This program is free software; you can redistribute it and/or modify
  12. ** it under the terms of the GNU General Public License as published by
  13. ** the Free Software Foundation; either version 2 of the License, or
  14. ** (at your option) any later version.
  15. **
  16. ** This program is distributed in the hope that it will be useful,
  17. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ** GNU General Public License for more details.
  20. **
  21. ** You should have received a copy of the GNU General Public License
  22. ** along with this program; if not, write to the Free Software
  23. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. **
  25. **-----------------------------------------------------------------------------
  26. */
  27. #include <linux/module.h>
  28. #include <linux/device.h>
  29. #include <linux/mca.h>
  30. /**
  31. * mca_device_read_stored_pos - read POS register from stored data
  32. * @mca_dev: device to read from
  33. * @reg: register to read from
  34. *
  35. * Fetch a POS value that was stored at boot time by the kernel
  36. * when it scanned the MCA space. The register value is returned.
  37. * Missing or invalid registers report 0.
  38. */
  39. unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
  40. {
  41. if(reg < 0 || reg >= 8)
  42. return 0;
  43. return mca_dev->pos[reg];
  44. }
  45. EXPORT_SYMBOL(mca_device_read_stored_pos);
  46. /**
  47. * mca_device_read_pos - read POS register from card
  48. * @mca_dev: device to read from
  49. * @reg: register to read from
  50. *
  51. * Fetch a POS value directly from the hardware to obtain the
  52. * current value. This is much slower than
  53. * mca_device_read_stored_pos and may not be invoked from
  54. * interrupt context. It handles the deep magic required for
  55. * onboard devices transparently.
  56. */
  57. unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
  58. {
  59. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  60. return mca_bus->f.mca_read_pos(mca_dev, reg);
  61. return mca_dev->pos[reg];
  62. }
  63. EXPORT_SYMBOL(mca_device_read_pos);
  64. /**
  65. * mca_device_write_pos - read POS register from card
  66. * @mca_dev: device to write pos register to
  67. * @reg: register to write to
  68. * @byte: byte to write to the POS registers
  69. *
  70. * Store a POS value directly to the hardware. You should not
  71. * normally need to use this function and should have a very good
  72. * knowledge of MCA bus before you do so. Doing this wrongly can
  73. * damage the hardware.
  74. *
  75. * This function may not be used from interrupt context.
  76. *
  77. */
  78. void mca_device_write_pos(struct mca_device *mca_dev, int reg,
  79. unsigned char byte)
  80. {
  81. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  82. mca_bus->f.mca_write_pos(mca_dev, reg, byte);
  83. }
  84. EXPORT_SYMBOL(mca_device_write_pos);
  85. /**
  86. * mca_device_transform_irq - transform the ADF obtained IRQ
  87. * @mca_device: device whose irq needs transforming
  88. * @irq: input irq from ADF
  89. *
  90. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  91. * etc. definitions. In systems with more than one bus, these need
  92. * to be transformed through bus mapping functions to get the real
  93. * system global quantities.
  94. *
  95. * This function transforms the interrupt number and returns the
  96. * transformed system global interrupt
  97. */
  98. int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
  99. {
  100. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  101. return mca_bus->f.mca_transform_irq(mca_dev, irq);
  102. }
  103. EXPORT_SYMBOL(mca_device_transform_irq);
  104. /**
  105. * mca_device_transform_ioport - transform the ADF obtained I/O port
  106. * @mca_device: device whose port needs transforming
  107. * @ioport: input I/O port from ADF
  108. *
  109. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  110. * etc. definitions. In systems with more than one bus, these need
  111. * to be transformed through bus mapping functions to get the real
  112. * system global quantities.
  113. *
  114. * This function transforms the I/O port number and returns the
  115. * transformed system global port number.
  116. *
  117. * This transformation can be assumed to be linear for port ranges.
  118. */
  119. int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
  120. {
  121. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  122. return mca_bus->f.mca_transform_ioport(mca_dev, port);
  123. }
  124. EXPORT_SYMBOL(mca_device_transform_ioport);
  125. /**
  126. * mca_device_transform_memory - transform the ADF obtained memory
  127. * @mca_device: device whose memory region needs transforming
  128. * @mem: memory region start from ADF
  129. *
  130. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  131. * etc. definitions. In systems with more than one bus, these need
  132. * to be transformed through bus mapping functions to get the real
  133. * system global quantities.
  134. *
  135. * This function transforms the memory region start and returns the
  136. * transformed system global memory region (physical).
  137. *
  138. * This transformation can be assumed to be linear for region ranges.
  139. */
  140. void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
  141. {
  142. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  143. return mca_bus->f.mca_transform_memory(mca_dev, mem);
  144. }
  145. EXPORT_SYMBOL(mca_device_transform_memory);
  146. /**
  147. * mca_device_claimed - check if claimed by driver
  148. * @mca_dev: device to check
  149. *
  150. * Returns 1 if the slot has been claimed by a driver
  151. */
  152. int mca_device_claimed(struct mca_device *mca_dev)
  153. {
  154. return mca_dev->driver_loaded;
  155. }
  156. EXPORT_SYMBOL(mca_device_claimed);
  157. /**
  158. * mca_device_set_claim - set the claim value of the driver
  159. * @mca_dev: device to set value for
  160. * @val: claim value to set (1 claimed, 0 unclaimed)
  161. */
  162. void mca_device_set_claim(struct mca_device *mca_dev, int val)
  163. {
  164. mca_dev->driver_loaded = val;
  165. }
  166. EXPORT_SYMBOL(mca_device_set_claim);
  167. /**
  168. * mca_device_status - get the status of the device
  169. * @mca_device: device to get
  170. *
  171. * returns an enumeration of the device status:
  172. *
  173. * MCA_ADAPTER_NORMAL adapter is OK.
  174. * MCA_ADAPTER_NONE no adapter at device (should never happen).
  175. * MCA_ADAPTER_DISABLED adapter is disabled.
  176. * MCA_ADAPTER_ERROR adapter cannot be initialised.
  177. */
  178. enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
  179. {
  180. return mca_dev->status;
  181. }
  182. EXPORT_SYMBOL(mca_device_status);
  183. /**
  184. * mca_device_set_name - set the name of the device
  185. * @mca_device: device to set the name of
  186. * @name: name to set
  187. */
  188. void mca_device_set_name(struct mca_device *mca_dev, const char *name)
  189. {
  190. if(!mca_dev)
  191. return;
  192. strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
  193. }
  194. EXPORT_SYMBOL(mca_device_set_name);