mca-device.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. #include <linux/string.h>
  31. /**
  32. * mca_device_read_stored_pos - read POS register from stored data
  33. * @mca_dev: device to read from
  34. * @reg: register to read from
  35. *
  36. * Fetch a POS value that was stored at boot time by the kernel
  37. * when it scanned the MCA space. The register value is returned.
  38. * Missing or invalid registers report 0.
  39. */
  40. unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
  41. {
  42. if(reg < 0 || reg >= 8)
  43. return 0;
  44. return mca_dev->pos[reg];
  45. }
  46. EXPORT_SYMBOL(mca_device_read_stored_pos);
  47. /**
  48. * mca_device_read_pos - read POS register from card
  49. * @mca_dev: device to read from
  50. * @reg: register to read from
  51. *
  52. * Fetch a POS value directly from the hardware to obtain the
  53. * current value. This is much slower than
  54. * mca_device_read_stored_pos and may not be invoked from
  55. * interrupt context. It handles the deep magic required for
  56. * onboard devices transparently.
  57. */
  58. unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
  59. {
  60. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  61. return mca_bus->f.mca_read_pos(mca_dev, reg);
  62. return mca_dev->pos[reg];
  63. }
  64. EXPORT_SYMBOL(mca_device_read_pos);
  65. /**
  66. * mca_device_write_pos - read POS register from card
  67. * @mca_dev: device to write pos register to
  68. * @reg: register to write to
  69. * @byte: byte to write to the POS registers
  70. *
  71. * Store a POS value directly to the hardware. You should not
  72. * normally need to use this function and should have a very good
  73. * knowledge of MCA bus before you do so. Doing this wrongly can
  74. * damage the hardware.
  75. *
  76. * This function may not be used from interrupt context.
  77. *
  78. */
  79. void mca_device_write_pos(struct mca_device *mca_dev, int reg,
  80. unsigned char byte)
  81. {
  82. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  83. mca_bus->f.mca_write_pos(mca_dev, reg, byte);
  84. }
  85. EXPORT_SYMBOL(mca_device_write_pos);
  86. /**
  87. * mca_device_transform_irq - transform the ADF obtained IRQ
  88. * @mca_device: device whose irq needs transforming
  89. * @irq: input irq from ADF
  90. *
  91. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  92. * etc. definitions. In systems with more than one bus, these need
  93. * to be transformed through bus mapping functions to get the real
  94. * system global quantities.
  95. *
  96. * This function transforms the interrupt number and returns the
  97. * transformed system global interrupt
  98. */
  99. int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
  100. {
  101. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  102. return mca_bus->f.mca_transform_irq(mca_dev, irq);
  103. }
  104. EXPORT_SYMBOL(mca_device_transform_irq);
  105. /**
  106. * mca_device_transform_ioport - transform the ADF obtained I/O port
  107. * @mca_device: device whose port needs transforming
  108. * @ioport: input I/O port from ADF
  109. *
  110. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  111. * etc. definitions. In systems with more than one bus, these need
  112. * to be transformed through bus mapping functions to get the real
  113. * system global quantities.
  114. *
  115. * This function transforms the I/O port number and returns the
  116. * transformed system global port number.
  117. *
  118. * This transformation can be assumed to be linear for port ranges.
  119. */
  120. int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
  121. {
  122. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  123. return mca_bus->f.mca_transform_ioport(mca_dev, port);
  124. }
  125. EXPORT_SYMBOL(mca_device_transform_ioport);
  126. /**
  127. * mca_device_transform_memory - transform the ADF obtained memory
  128. * @mca_device: device whose memory region needs transforming
  129. * @mem: memory region start from ADF
  130. *
  131. * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
  132. * etc. definitions. In systems with more than one bus, these need
  133. * to be transformed through bus mapping functions to get the real
  134. * system global quantities.
  135. *
  136. * This function transforms the memory region start and returns the
  137. * transformed system global memory region (physical).
  138. *
  139. * This transformation can be assumed to be linear for region ranges.
  140. */
  141. void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
  142. {
  143. struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
  144. return mca_bus->f.mca_transform_memory(mca_dev, mem);
  145. }
  146. EXPORT_SYMBOL(mca_device_transform_memory);
  147. /**
  148. * mca_device_claimed - check if claimed by driver
  149. * @mca_dev: device to check
  150. *
  151. * Returns 1 if the slot has been claimed by a driver
  152. */
  153. int mca_device_claimed(struct mca_device *mca_dev)
  154. {
  155. return mca_dev->driver_loaded;
  156. }
  157. EXPORT_SYMBOL(mca_device_claimed);
  158. /**
  159. * mca_device_set_claim - set the claim value of the driver
  160. * @mca_dev: device to set value for
  161. * @val: claim value to set (1 claimed, 0 unclaimed)
  162. */
  163. void mca_device_set_claim(struct mca_device *mca_dev, int val)
  164. {
  165. mca_dev->driver_loaded = val;
  166. }
  167. EXPORT_SYMBOL(mca_device_set_claim);
  168. /**
  169. * mca_device_status - get the status of the device
  170. * @mca_device: device to get
  171. *
  172. * returns an enumeration of the device status:
  173. *
  174. * MCA_ADAPTER_NORMAL adapter is OK.
  175. * MCA_ADAPTER_NONE no adapter at device (should never happen).
  176. * MCA_ADAPTER_DISABLED adapter is disabled.
  177. * MCA_ADAPTER_ERROR adapter cannot be initialised.
  178. */
  179. enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
  180. {
  181. return mca_dev->status;
  182. }
  183. EXPORT_SYMBOL(mca_device_status);
  184. /**
  185. * mca_device_set_name - set the name of the device
  186. * @mca_device: device to set the name of
  187. * @name: name to set
  188. */
  189. void mca_device_set_name(struct mca_device *mca_dev, const char *name)
  190. {
  191. if(!mca_dev)
  192. return;
  193. strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
  194. }
  195. EXPORT_SYMBOL(mca_device_set_name);