mca_32.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * Written by Martin Kolinek, February 1996
  3. *
  4. * Changes:
  5. *
  6. * Chris Beauregard July 28th, 1996
  7. * - Fixed up integrated SCSI detection
  8. *
  9. * Chris Beauregard August 3rd, 1996
  10. * - Made mca_info local
  11. * - Made integrated registers accessible through standard function calls
  12. * - Added name field
  13. * - More sanity checking
  14. *
  15. * Chris Beauregard August 9th, 1996
  16. * - Rewrote /proc/mca
  17. *
  18. * Chris Beauregard January 7th, 1997
  19. * - Added basic NMI-processing
  20. * - Added more information to mca_info structure
  21. *
  22. * David Weinehall October 12th, 1998
  23. * - Made a lot of cleaning up in the source
  24. * - Added use of save_flags / restore_flags
  25. * - Added the 'driver_loaded' flag in MCA_adapter
  26. * - Added an alternative implemention of ZP Gu's mca_find_unused_adapter
  27. *
  28. * David Weinehall March 24th, 1999
  29. * - Fixed the output of 'Driver Installed' in /proc/mca/pos
  30. * - Made the Integrated Video & SCSI show up even if they have id 0000
  31. *
  32. * Alexander Viro November 9th, 1999
  33. * - Switched to regular procfs methods
  34. *
  35. * Alfred Arnold & David Weinehall August 23rd, 2000
  36. * - Added support for Planar POS-registers
  37. */
  38. #include <linux/module.h>
  39. #include <linux/types.h>
  40. #include <linux/errno.h>
  41. #include <linux/kernel.h>
  42. #include <linux/mca.h>
  43. #include <linux/kprobes.h>
  44. #include <linux/slab.h>
  45. #include <asm/system.h>
  46. #include <asm/io.h>
  47. #include <linux/proc_fs.h>
  48. #include <linux/mman.h>
  49. #include <linux/mm.h>
  50. #include <linux/pagemap.h>
  51. #include <linux/ioport.h>
  52. #include <asm/uaccess.h>
  53. #include <linux/init.h>
  54. static unsigned char which_scsi;
  55. int MCA_bus;
  56. EXPORT_SYMBOL(MCA_bus);
  57. /*
  58. * Motherboard register spinlock. Untested on SMP at the moment, but
  59. * are there any MCA SMP boxes?
  60. *
  61. * Yes - Alan
  62. */
  63. static DEFINE_SPINLOCK(mca_lock);
  64. /* Build the status info for the adapter */
  65. static void mca_configure_adapter_status(struct mca_device *mca_dev)
  66. {
  67. mca_dev->status = MCA_ADAPTER_NONE;
  68. mca_dev->pos_id = mca_dev->pos[0]
  69. + (mca_dev->pos[1] << 8);
  70. if (!mca_dev->pos_id && mca_dev->slot < MCA_MAX_SLOT_NR) {
  71. /*
  72. * id = 0x0000 usually indicates hardware failure,
  73. * however, ZP Gu (zpg@castle.net> reports that his 9556
  74. * has 0x0000 as id and everything still works. There
  75. * also seem to be an adapter with id = 0x0000; the
  76. * NCR Parallel Bus Memory Card. Until this is confirmed,
  77. * however, this code will stay.
  78. */
  79. mca_dev->status = MCA_ADAPTER_ERROR;
  80. return;
  81. } else if (mca_dev->pos_id != 0xffff) {
  82. /*
  83. * 0xffff usually indicates that there's no adapter,
  84. * however, some integrated adapters may have 0xffff as
  85. * their id and still be valid. Examples are on-board
  86. * VGA of the 55sx, the integrated SCSI of the 56 & 57,
  87. * and possibly also the 95 ULTIMEDIA.
  88. */
  89. mca_dev->status = MCA_ADAPTER_NORMAL;
  90. }
  91. if ((mca_dev->pos_id == 0xffff ||
  92. mca_dev->pos_id == 0x0000) && mca_dev->slot >= MCA_MAX_SLOT_NR) {
  93. int j;
  94. for (j = 2; j < 8; j++) {
  95. if (mca_dev->pos[j] != 0xff) {
  96. mca_dev->status = MCA_ADAPTER_NORMAL;
  97. break;
  98. }
  99. }
  100. }
  101. if (!(mca_dev->pos[2] & MCA_ENABLED)) {
  102. /* enabled bit is in POS 2 */
  103. mca_dev->status = MCA_ADAPTER_DISABLED;
  104. }
  105. } /* mca_configure_adapter_status */
  106. /*--------------------------------------------------------------------*/
  107. static struct resource mca_standard_resources[] = {
  108. { .start = 0x60, .end = 0x60, .name = "system control port B (MCA)" },
  109. { .start = 0x90, .end = 0x90, .name = "arbitration (MCA)" },
  110. { .start = 0x91, .end = 0x91, .name = "card Select Feedback (MCA)" },
  111. { .start = 0x92, .end = 0x92, .name = "system Control port A (MCA)" },
  112. { .start = 0x94, .end = 0x94, .name = "system board setup (MCA)" },
  113. { .start = 0x96, .end = 0x97, .name = "POS (MCA)" },
  114. { .start = 0x100, .end = 0x107, .name = "POS (MCA)" }
  115. };
  116. #define MCA_STANDARD_RESOURCES ARRAY_SIZE(mca_standard_resources)
  117. /*
  118. * mca_read_and_store_pos - read the POS registers into a memory buffer
  119. * @pos: a char pointer to 8 bytes, contains the POS register value on
  120. * successful return
  121. *
  122. * Returns 1 if a card actually exists (i.e. the pos isn't
  123. * all 0xff) or 0 otherwise
  124. */
  125. static int mca_read_and_store_pos(unsigned char *pos)
  126. {
  127. int j;
  128. int found = 0;
  129. for (j = 0; j < 8; j++) {
  130. pos[j] = inb_p(MCA_POS_REG(j));
  131. if (pos[j] != 0xff) {
  132. /* 0xff all across means no device. 0x00 means
  133. * something's broken, but a device is
  134. * probably there. However, if you get 0x00
  135. * from a motherboard register it won't matter
  136. * what we find. For the record, on the
  137. * 57SLC, the integrated SCSI adapter has
  138. * 0xffff for the adapter ID, but nonzero for
  139. * other registers. */
  140. found = 1;
  141. }
  142. }
  143. return found;
  144. }
  145. static unsigned char mca_pc_read_pos(struct mca_device *mca_dev, int reg)
  146. {
  147. unsigned char byte;
  148. unsigned long flags;
  149. if (reg < 0 || reg >= 8)
  150. return 0;
  151. spin_lock_irqsave(&mca_lock, flags);
  152. if (mca_dev->pos_register) {
  153. /* Disable adapter setup, enable motherboard setup */
  154. outb_p(0, MCA_ADAPTER_SETUP_REG);
  155. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  156. byte = inb_p(MCA_POS_REG(reg));
  157. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  158. } else {
  159. /* Make sure motherboard setup is off */
  160. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  161. /* Read the appropriate register */
  162. outb_p(0x8|(mca_dev->slot & 0xf), MCA_ADAPTER_SETUP_REG);
  163. byte = inb_p(MCA_POS_REG(reg));
  164. outb_p(0, MCA_ADAPTER_SETUP_REG);
  165. }
  166. spin_unlock_irqrestore(&mca_lock, flags);
  167. mca_dev->pos[reg] = byte;
  168. return byte;
  169. }
  170. static void mca_pc_write_pos(struct mca_device *mca_dev, int reg,
  171. unsigned char byte)
  172. {
  173. unsigned long flags;
  174. if (reg < 0 || reg >= 8)
  175. return;
  176. spin_lock_irqsave(&mca_lock, flags);
  177. /* Make sure motherboard setup is off */
  178. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  179. /* Read in the appropriate register */
  180. outb_p(0x8|(mca_dev->slot&0xf), MCA_ADAPTER_SETUP_REG);
  181. outb_p(byte, MCA_POS_REG(reg));
  182. outb_p(0, MCA_ADAPTER_SETUP_REG);
  183. spin_unlock_irqrestore(&mca_lock, flags);
  184. /* Update the global register list, while we have the byte */
  185. mca_dev->pos[reg] = byte;
  186. }
  187. /* for the primary MCA bus, we have identity transforms */
  188. static int mca_dummy_transform_irq(struct mca_device *mca_dev, int irq)
  189. {
  190. return irq;
  191. }
  192. static int mca_dummy_transform_ioport(struct mca_device *mca_dev, int port)
  193. {
  194. return port;
  195. }
  196. static void *mca_dummy_transform_memory(struct mca_device *mca_dev, void *mem)
  197. {
  198. return mem;
  199. }
  200. static int __init mca_init(void)
  201. {
  202. unsigned int i, j;
  203. struct mca_device *mca_dev;
  204. unsigned char pos[8];
  205. short mca_builtin_scsi_ports[] = {0xf7, 0xfd, 0x00};
  206. struct mca_bus *bus;
  207. /*
  208. * WARNING: Be careful when making changes here. Putting an adapter
  209. * and the motherboard simultaneously into setup mode may result in
  210. * damage to chips (according to The Indispensable PC Hardware Book
  211. * by Hans-Peter Messmer). Also, we disable system interrupts (so
  212. * that we are not disturbed in the middle of this).
  213. */
  214. /* Make sure the MCA bus is present */
  215. if (mca_system_init()) {
  216. printk(KERN_ERR "MCA bus system initialisation failed\n");
  217. return -ENODEV;
  218. }
  219. if (!MCA_bus)
  220. return -ENODEV;
  221. printk(KERN_INFO "Micro Channel bus detected.\n");
  222. /* All MCA systems have at least a primary bus */
  223. bus = mca_attach_bus(MCA_PRIMARY_BUS);
  224. if (!bus)
  225. goto out_nomem;
  226. bus->default_dma_mask = 0xffffffffLL;
  227. bus->f.mca_write_pos = mca_pc_write_pos;
  228. bus->f.mca_read_pos = mca_pc_read_pos;
  229. bus->f.mca_transform_irq = mca_dummy_transform_irq;
  230. bus->f.mca_transform_ioport = mca_dummy_transform_ioport;
  231. bus->f.mca_transform_memory = mca_dummy_transform_memory;
  232. /* get the motherboard device */
  233. mca_dev = kzalloc(sizeof(struct mca_device), GFP_KERNEL);
  234. if (unlikely(!mca_dev))
  235. goto out_nomem;
  236. /*
  237. * We do not expect many MCA interrupts during initialization,
  238. * but let us be safe:
  239. */
  240. spin_lock_irq(&mca_lock);
  241. /* Make sure adapter setup is off */
  242. outb_p(0, MCA_ADAPTER_SETUP_REG);
  243. /* Read motherboard POS registers */
  244. mca_dev->pos_register = 0x7f;
  245. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  246. mca_dev->name[0] = 0;
  247. mca_read_and_store_pos(mca_dev->pos);
  248. mca_configure_adapter_status(mca_dev);
  249. /* fake POS and slot for a motherboard */
  250. mca_dev->pos_id = MCA_MOTHERBOARD_POS;
  251. mca_dev->slot = MCA_MOTHERBOARD;
  252. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  253. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  254. if (unlikely(!mca_dev))
  255. goto out_unlock_nomem;
  256. /* Put motherboard into video setup mode, read integrated video
  257. * POS registers, and turn motherboard setup off.
  258. */
  259. mca_dev->pos_register = 0xdf;
  260. outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
  261. mca_dev->name[0] = 0;
  262. mca_read_and_store_pos(mca_dev->pos);
  263. mca_configure_adapter_status(mca_dev);
  264. /* fake POS and slot for the integrated video */
  265. mca_dev->pos_id = MCA_INTEGVIDEO_POS;
  266. mca_dev->slot = MCA_INTEGVIDEO;
  267. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  268. /*
  269. * Put motherboard into scsi setup mode, read integrated scsi
  270. * POS registers, and turn motherboard setup off.
  271. *
  272. * It seems there are two possible SCSI registers. Martin says that
  273. * for the 56,57, 0xf7 is the one, but fails on the 76.
  274. * Alfredo (apena@vnet.ibm.com) says
  275. * 0xfd works on his machine. We'll try both of them. I figure it's
  276. * a good bet that only one could be valid at a time. This could
  277. * screw up though if one is used for something else on the other
  278. * machine.
  279. */
  280. for (i = 0; (which_scsi = mca_builtin_scsi_ports[i]) != 0; i++) {
  281. outb_p(which_scsi, MCA_MOTHERBOARD_SETUP_REG);
  282. if (mca_read_and_store_pos(pos))
  283. break;
  284. }
  285. if (which_scsi) {
  286. /* found a scsi card */
  287. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  288. if (unlikely(!mca_dev))
  289. goto out_unlock_nomem;
  290. for (j = 0; j < 8; j++)
  291. mca_dev->pos[j] = pos[j];
  292. mca_configure_adapter_status(mca_dev);
  293. /* fake POS and slot for integrated SCSI controller */
  294. mca_dev->pos_id = MCA_INTEGSCSI_POS;
  295. mca_dev->slot = MCA_INTEGSCSI;
  296. mca_dev->pos_register = which_scsi;
  297. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  298. }
  299. /* Turn off motherboard setup */
  300. outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
  301. /*
  302. * Now loop over MCA slots: put each adapter into setup mode, and
  303. * read its POS registers. Then put adapter setup off.
  304. */
  305. for (i = 0; i < MCA_MAX_SLOT_NR; i++) {
  306. outb_p(0x8|(i&0xf), MCA_ADAPTER_SETUP_REG);
  307. if (!mca_read_and_store_pos(pos))
  308. continue;
  309. mca_dev = kzalloc(sizeof(struct mca_device), GFP_ATOMIC);
  310. if (unlikely(!mca_dev))
  311. goto out_unlock_nomem;
  312. for (j = 0; j < 8; j++)
  313. mca_dev->pos[j] = pos[j];
  314. mca_dev->driver_loaded = 0;
  315. mca_dev->slot = i;
  316. mca_dev->pos_register = 0;
  317. mca_configure_adapter_status(mca_dev);
  318. mca_register_device(MCA_PRIMARY_BUS, mca_dev);
  319. }
  320. outb_p(0, MCA_ADAPTER_SETUP_REG);
  321. /* Enable interrupts and return memory start */
  322. spin_unlock_irq(&mca_lock);
  323. for (i = 0; i < MCA_STANDARD_RESOURCES; i++)
  324. request_resource(&ioport_resource, mca_standard_resources + i);
  325. mca_do_proc_init();
  326. return 0;
  327. out_unlock_nomem:
  328. spin_unlock_irq(&mca_lock);
  329. out_nomem:
  330. printk(KERN_EMERG "Failed memory allocation in MCA setup!\n");
  331. return -ENOMEM;
  332. }
  333. subsys_initcall(mca_init);
  334. /*--------------------------------------------------------------------*/
  335. static __kprobes void
  336. mca_handle_nmi_device(struct mca_device *mca_dev, int check_flag)
  337. {
  338. int slot = mca_dev->slot;
  339. if (slot == MCA_INTEGSCSI) {
  340. printk(KERN_CRIT "NMI: caused by MCA integrated SCSI adapter (%s)\n",
  341. mca_dev->name);
  342. } else if (slot == MCA_INTEGVIDEO) {
  343. printk(KERN_CRIT "NMI: caused by MCA integrated video adapter (%s)\n",
  344. mca_dev->name);
  345. } else if (slot == MCA_MOTHERBOARD) {
  346. printk(KERN_CRIT "NMI: caused by motherboard (%s)\n",
  347. mca_dev->name);
  348. }
  349. /* More info available in POS 6 and 7? */
  350. if (check_flag) {
  351. unsigned char pos6, pos7;
  352. pos6 = mca_device_read_pos(mca_dev, 6);
  353. pos7 = mca_device_read_pos(mca_dev, 7);
  354. printk(KERN_CRIT "NMI: POS 6 = 0x%x, POS 7 = 0x%x\n", pos6, pos7);
  355. }
  356. } /* mca_handle_nmi_slot */
  357. /*--------------------------------------------------------------------*/
  358. static int __kprobes mca_handle_nmi_callback(struct device *dev, void *data)
  359. {
  360. struct mca_device *mca_dev = to_mca_device(dev);
  361. unsigned char pos5;
  362. pos5 = mca_device_read_pos(mca_dev, 5);
  363. if (!(pos5 & 0x80)) {
  364. /*
  365. * Bit 7 of POS 5 is reset when this adapter has a hardware
  366. * error. Bit 7 it reset if there's error information
  367. * available in POS 6 and 7.
  368. */
  369. mca_handle_nmi_device(mca_dev, !(pos5 & 0x40));
  370. return 1;
  371. }
  372. return 0;
  373. }
  374. void __kprobes mca_handle_nmi(void)
  375. {
  376. /*
  377. * First try - scan the various adapters and see if a specific
  378. * adapter was responsible for the error.
  379. */
  380. bus_for_each_dev(&mca_bus_type, NULL, NULL, mca_handle_nmi_callback);
  381. }