iop.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * I/O Processor (IOP) management
  3. * Written and (C) 1999 by Joshua M. Thompson (funaho@jurai.org)
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice and this list of conditions.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice and this list of conditions in the documentation and/or other
  12. * materials provided with the distribution.
  13. */
  14. /*
  15. * The IOP chips are used in the IIfx and some Quadras (900, 950) to manage
  16. * serial and ADB. They are actually a 6502 processor and some glue logic.
  17. *
  18. * 990429 (jmt) - Initial implementation, just enough to knock the SCC IOP
  19. * into compatible mode so nobody has to fiddle with the
  20. * Serial Switch control panel anymore.
  21. * 990603 (jmt) - Added code to grab the correct ISM IOP interrupt for OSS
  22. * and non-OSS machines (at least I hope it's correct on a
  23. * non-OSS machine -- someone with a Q900 or Q950 needs to
  24. * check this.)
  25. * 990605 (jmt) - Rearranged things a bit wrt IOP detection; iop_present is
  26. * gone, IOP base addresses are now in an array and the
  27. * globally-visible functions take an IOP number instead of an
  28. * an actual base address.
  29. * 990610 (jmt) - Finished the message passing framework and it seems to work.
  30. * Sending _definitely_ works; my adb-bus.c mods can send
  31. * messages and receive the MSG_COMPLETED status back from the
  32. * IOP. The trick now is figuring out the message formats.
  33. * 990611 (jmt) - More cleanups. Fixed problem where unclaimed messages on a
  34. * receive channel were never properly acknowledged. Bracketed
  35. * the remaining debug printk's with #ifdef's and disabled
  36. * debugging. I can now type on the console.
  37. * 990612 (jmt) - Copyright notice added. Reworked the way replies are handled.
  38. * It turns out that replies are placed back in the send buffer
  39. * for that channel; messages on the receive channels are always
  40. * unsolicited messages from the IOP (and our replies to them
  41. * should go back in the receive channel.) Also added tracking
  42. * of device names to the listener functions ala the interrupt
  43. * handlers.
  44. * 990729 (jmt) - Added passing of pt_regs structure to IOP handlers. This is
  45. * used by the new unified ADB driver.
  46. *
  47. * TODO:
  48. *
  49. * o Something should be periodically checking iop_alive() to make sure the
  50. * IOP hasn't died.
  51. * o Some of the IOP manager routines need better error checking and
  52. * return codes. Nothing major, just prettying up.
  53. */
  54. /*
  55. * -----------------------
  56. * IOP Message Passing 101
  57. * -----------------------
  58. *
  59. * The host talks to the IOPs using a rather simple message-passing scheme via
  60. * a shared memory area in the IOP RAM. Each IOP has seven "channels"; each
  61. * channel is conneced to a specific software driver on the IOP. For example
  62. * on the SCC IOP there is one channel for each serial port. Each channel has
  63. * an incoming and and outgoing message queue with a depth of one.
  64. *
  65. * A message is 32 bytes plus a state byte for the channel (MSG_IDLE, MSG_NEW,
  66. * MSG_RCVD, MSG_COMPLETE). To send a message you copy the message into the
  67. * buffer, set the state to MSG_NEW and signal the IOP by setting the IRQ flag
  68. * in the IOP control to 1. The IOP will move the state to MSG_RCVD when it
  69. * receives the message and then to MSG_COMPLETE when the message processing
  70. * has completed. It is the host's responsibility at that point to read the
  71. * reply back out of the send channel buffer and reset the channel state back
  72. * to MSG_IDLE.
  73. *
  74. * To receive message from the IOP the same procedure is used except the roles
  75. * are reversed. That is, the IOP puts message in the channel with a state of
  76. * MSG_NEW, and the host receives the message and move its state to MSG_RCVD
  77. * and then to MSG_COMPLETE when processing is completed and the reply (if any)
  78. * has been placed back in the receive channel. The IOP will then reset the
  79. * channel state to MSG_IDLE.
  80. *
  81. * Two sets of host interrupts are provided, INT0 and INT1. Both appear on one
  82. * interrupt level; they are distinguished by a pair of bits in the IOP status
  83. * register. The IOP will raise INT0 when one or more messages in the send
  84. * channels have gone to the MSG_COMPLETE state and it will raise INT1 when one
  85. * or more messages on the receive channels have gone to the MSG_NEW state.
  86. *
  87. * Since each channel handles only one message we have to implement a small
  88. * interrupt-driven queue on our end. Messages to be sent are placed on the
  89. * queue for sending and contain a pointer to an optional callback function.
  90. * The handler for a message is called when the message state goes to
  91. * MSG_COMPLETE.
  92. *
  93. * For receiving message we maintain a list of handler functions to call when
  94. * a message is received on that IOP/channel combination. The handlers are
  95. * called much like an interrupt handler and are passed a copy of the message
  96. * from the IOP. The message state will be in MSG_RCVD while the handler runs;
  97. * it is the handler's responsibility to call iop_complete_message() when
  98. * finished; this function moves the message state to MSG_COMPLETE and signals
  99. * the IOP. This two-step process is provided to allow the handler to defer
  100. * message processing to a bottom-half handler if the processing will take
  101. * a signifigant amount of time (handlers are called at interrupt time so they
  102. * should execute quickly.)
  103. */
  104. #include <linux/config.h>
  105. #include <linux/types.h>
  106. #include <linux/kernel.h>
  107. #include <linux/mm.h>
  108. #include <linux/delay.h>
  109. #include <linux/init.h>
  110. #include <linux/proc_fs.h>
  111. #include <linux/interrupt.h>
  112. #include <asm/bootinfo.h>
  113. #include <asm/macintosh.h>
  114. #include <asm/macints.h>
  115. #include <asm/mac_iop.h>
  116. #include <asm/mac_oss.h>
  117. /*#define DEBUG_IOP*/
  118. /* Set to nonezero if the IOPs are present. Set by iop_init() */
  119. int iop_scc_present,iop_ism_present;
  120. #ifdef CONFIG_PROC_FS
  121. static int iop_get_proc_info(char *, char **, off_t, int);
  122. #endif /* CONFIG_PROC_FS */
  123. /* structure for tracking channel listeners */
  124. struct listener {
  125. const char *devname;
  126. void (*handler)(struct iop_msg *, struct pt_regs *);
  127. };
  128. /*
  129. * IOP structures for the two IOPs
  130. *
  131. * The SCC IOP controls both serial ports (A and B) as its two functions.
  132. * The ISM IOP controls the SWIM (floppy drive) and ADB.
  133. */
  134. static volatile struct mac_iop *iop_base[NUM_IOPS];
  135. /*
  136. * IOP message queues
  137. */
  138. static struct iop_msg iop_msg_pool[NUM_IOP_MSGS];
  139. static struct iop_msg *iop_send_queue[NUM_IOPS][NUM_IOP_CHAN];
  140. static struct listener iop_listeners[NUM_IOPS][NUM_IOP_CHAN];
  141. irqreturn_t iop_ism_irq(int, void *, struct pt_regs *);
  142. extern void oss_irq_enable(int);
  143. /*
  144. * Private access functions
  145. */
  146. static __inline__ void iop_loadaddr(volatile struct mac_iop *iop, __u16 addr)
  147. {
  148. iop->ram_addr_lo = addr;
  149. iop->ram_addr_hi = addr >> 8;
  150. }
  151. static __inline__ __u8 iop_readb(volatile struct mac_iop *iop, __u16 addr)
  152. {
  153. iop->ram_addr_lo = addr;
  154. iop->ram_addr_hi = addr >> 8;
  155. return iop->ram_data;
  156. }
  157. static __inline__ void iop_writeb(volatile struct mac_iop *iop, __u16 addr, __u8 data)
  158. {
  159. iop->ram_addr_lo = addr;
  160. iop->ram_addr_hi = addr >> 8;
  161. iop->ram_data = data;
  162. }
  163. static __inline__ void iop_stop(volatile struct mac_iop *iop)
  164. {
  165. iop->status_ctrl &= ~IOP_RUN;
  166. }
  167. static __inline__ void iop_start(volatile struct mac_iop *iop)
  168. {
  169. iop->status_ctrl = IOP_RUN | IOP_AUTOINC;
  170. }
  171. static __inline__ void iop_bypass(volatile struct mac_iop *iop)
  172. {
  173. iop->status_ctrl |= IOP_BYPASS;
  174. }
  175. static __inline__ void iop_interrupt(volatile struct mac_iop *iop)
  176. {
  177. iop->status_ctrl |= IOP_IRQ;
  178. }
  179. static int iop_alive(volatile struct mac_iop *iop)
  180. {
  181. int retval;
  182. retval = (iop_readb(iop, IOP_ADDR_ALIVE) == 0xFF);
  183. iop_writeb(iop, IOP_ADDR_ALIVE, 0);
  184. return retval;
  185. }
  186. static struct iop_msg *iop_alloc_msg(void)
  187. {
  188. int i;
  189. unsigned long flags;
  190. local_irq_save(flags);
  191. for (i = 0 ; i < NUM_IOP_MSGS ; i++) {
  192. if (iop_msg_pool[i].status == IOP_MSGSTATUS_UNUSED) {
  193. iop_msg_pool[i].status = IOP_MSGSTATUS_WAITING;
  194. local_irq_restore(flags);
  195. return &iop_msg_pool[i];
  196. }
  197. }
  198. local_irq_restore(flags);
  199. return NULL;
  200. }
  201. static void iop_free_msg(struct iop_msg *msg)
  202. {
  203. msg->status = IOP_MSGSTATUS_UNUSED;
  204. }
  205. /*
  206. * This is called by the startup code before anything else. Its purpose
  207. * is to find and initialize the IOPs early in the boot sequence, so that
  208. * the serial IOP can be placed into bypass mode _before_ we try to
  209. * initialize the serial console.
  210. */
  211. void __init iop_preinit(void)
  212. {
  213. if (macintosh_config->scc_type == MAC_SCC_IOP) {
  214. if (macintosh_config->ident == MAC_MODEL_IIFX) {
  215. iop_base[IOP_NUM_SCC] = (struct mac_iop *) SCC_IOP_BASE_IIFX;
  216. } else {
  217. iop_base[IOP_NUM_SCC] = (struct mac_iop *) SCC_IOP_BASE_QUADRA;
  218. }
  219. iop_base[IOP_NUM_SCC]->status_ctrl = 0x87;
  220. iop_scc_present = 1;
  221. } else {
  222. iop_base[IOP_NUM_SCC] = NULL;
  223. iop_scc_present = 0;
  224. }
  225. if (macintosh_config->adb_type == MAC_ADB_IOP) {
  226. if (macintosh_config->ident == MAC_MODEL_IIFX) {
  227. iop_base[IOP_NUM_ISM] = (struct mac_iop *) ISM_IOP_BASE_IIFX;
  228. } else {
  229. iop_base[IOP_NUM_ISM] = (struct mac_iop *) ISM_IOP_BASE_QUADRA;
  230. }
  231. iop_base[IOP_NUM_ISM]->status_ctrl = 0;
  232. iop_ism_present = 1;
  233. } else {
  234. iop_base[IOP_NUM_ISM] = NULL;
  235. iop_ism_present = 0;
  236. }
  237. }
  238. /*
  239. * Initialize the IOPs, if present.
  240. */
  241. void __init iop_init(void)
  242. {
  243. int i;
  244. if (iop_scc_present) {
  245. printk("IOP: detected SCC IOP at %p\n", iop_base[IOP_NUM_SCC]);
  246. }
  247. if (iop_ism_present) {
  248. printk("IOP: detected ISM IOP at %p\n", iop_base[IOP_NUM_ISM]);
  249. iop_start(iop_base[IOP_NUM_ISM]);
  250. iop_alive(iop_base[IOP_NUM_ISM]); /* clears the alive flag */
  251. }
  252. /* Make the whole pool available and empty the queues */
  253. for (i = 0 ; i < NUM_IOP_MSGS ; i++) {
  254. iop_msg_pool[i].status = IOP_MSGSTATUS_UNUSED;
  255. }
  256. for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
  257. iop_send_queue[IOP_NUM_SCC][i] = 0;
  258. iop_send_queue[IOP_NUM_ISM][i] = 0;
  259. iop_listeners[IOP_NUM_SCC][i].devname = NULL;
  260. iop_listeners[IOP_NUM_SCC][i].handler = NULL;
  261. iop_listeners[IOP_NUM_ISM][i].devname = NULL;
  262. iop_listeners[IOP_NUM_ISM][i].handler = NULL;
  263. }
  264. #if 0 /* Crashing in 2.4 now, not yet sure why. --jmt */
  265. #ifdef CONFIG_PROC_FS
  266. create_proc_info_entry("mac_iop", 0, &proc_root, iop_get_proc_info);
  267. #endif
  268. #endif
  269. }
  270. /*
  271. * Register the interrupt handler for the IOPs.
  272. * TODO: might be wrong for non-OSS machines. Anyone?
  273. */
  274. void __init iop_register_interrupts(void)
  275. {
  276. if (iop_ism_present) {
  277. if (oss_present) {
  278. cpu_request_irq(OSS_IRQLEV_IOPISM, iop_ism_irq,
  279. IRQ_FLG_LOCK, "ISM IOP",
  280. (void *) IOP_NUM_ISM);
  281. oss_irq_enable(IRQ_MAC_ADB);
  282. } else {
  283. request_irq(IRQ_VIA2_0, iop_ism_irq,
  284. IRQ_FLG_LOCK|IRQ_FLG_FAST, "ISM IOP",
  285. (void *) IOP_NUM_ISM);
  286. }
  287. if (!iop_alive(iop_base[IOP_NUM_ISM])) {
  288. printk("IOP: oh my god, they killed the ISM IOP!\n");
  289. } else {
  290. printk("IOP: the ISM IOP seems to be alive.\n");
  291. }
  292. }
  293. }
  294. /*
  295. * Register or unregister a listener for a specific IOP and channel
  296. *
  297. * If the handler pointer is NULL the current listener (if any) is
  298. * unregistered. Otherwise the new listener is registered provided
  299. * there is no existing listener registered.
  300. */
  301. int iop_listen(uint iop_num, uint chan,
  302. void (*handler)(struct iop_msg *, struct pt_regs *),
  303. const char *devname)
  304. {
  305. if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return -EINVAL;
  306. if (chan >= NUM_IOP_CHAN) return -EINVAL;
  307. if (iop_listeners[iop_num][chan].handler && handler) return -EINVAL;
  308. iop_listeners[iop_num][chan].devname = devname;
  309. iop_listeners[iop_num][chan].handler = handler;
  310. return 0;
  311. }
  312. /*
  313. * Complete reception of a message, which just means copying the reply
  314. * into the buffer, setting the channel state to MSG_COMPLETE and
  315. * notifying the IOP.
  316. */
  317. void iop_complete_message(struct iop_msg *msg)
  318. {
  319. int iop_num = msg->iop_num;
  320. int chan = msg->channel;
  321. int i,offset;
  322. #ifdef DEBUG_IOP
  323. printk("iop_complete(%p): iop %d chan %d\n", msg, msg->iop_num, msg->channel);
  324. #endif
  325. offset = IOP_ADDR_RECV_MSG + (msg->channel * IOP_MSG_LEN);
  326. for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
  327. iop_writeb(iop_base[iop_num], offset, msg->reply[i]);
  328. }
  329. iop_writeb(iop_base[iop_num],
  330. IOP_ADDR_RECV_STATE + chan, IOP_MSG_COMPLETE);
  331. iop_interrupt(iop_base[msg->iop_num]);
  332. iop_free_msg(msg);
  333. }
  334. /*
  335. * Actually put a message into a send channel buffer
  336. */
  337. static void iop_do_send(struct iop_msg *msg)
  338. {
  339. volatile struct mac_iop *iop = iop_base[msg->iop_num];
  340. int i,offset;
  341. offset = IOP_ADDR_SEND_MSG + (msg->channel * IOP_MSG_LEN);
  342. for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
  343. iop_writeb(iop, offset, msg->message[i]);
  344. }
  345. iop_writeb(iop, IOP_ADDR_SEND_STATE + msg->channel, IOP_MSG_NEW);
  346. iop_interrupt(iop);
  347. }
  348. /*
  349. * Handle sending a message on a channel that
  350. * has gone into the IOP_MSG_COMPLETE state.
  351. */
  352. static void iop_handle_send(uint iop_num, uint chan, struct pt_regs *regs)
  353. {
  354. volatile struct mac_iop *iop = iop_base[iop_num];
  355. struct iop_msg *msg,*msg2;
  356. int i,offset;
  357. #ifdef DEBUG_IOP
  358. printk("iop_handle_send: iop %d channel %d\n", iop_num, chan);
  359. #endif
  360. iop_writeb(iop, IOP_ADDR_SEND_STATE + chan, IOP_MSG_IDLE);
  361. if (!(msg = iop_send_queue[iop_num][chan])) return;
  362. msg->status = IOP_MSGSTATUS_COMPLETE;
  363. offset = IOP_ADDR_SEND_MSG + (chan * IOP_MSG_LEN);
  364. for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
  365. msg->reply[i] = iop_readb(iop, offset);
  366. }
  367. if (msg->handler) (*msg->handler)(msg, regs);
  368. msg2 = msg;
  369. msg = msg->next;
  370. iop_free_msg(msg2);
  371. iop_send_queue[iop_num][chan] = msg;
  372. if (msg) iop_do_send(msg);
  373. }
  374. /*
  375. * Handle reception of a message on a channel that has
  376. * gone into the IOP_MSG_NEW state.
  377. */
  378. static void iop_handle_recv(uint iop_num, uint chan, struct pt_regs *regs)
  379. {
  380. volatile struct mac_iop *iop = iop_base[iop_num];
  381. int i,offset;
  382. struct iop_msg *msg;
  383. #ifdef DEBUG_IOP
  384. printk("iop_handle_recv: iop %d channel %d\n", iop_num, chan);
  385. #endif
  386. msg = iop_alloc_msg();
  387. msg->iop_num = iop_num;
  388. msg->channel = chan;
  389. msg->status = IOP_MSGSTATUS_UNSOL;
  390. msg->handler = iop_listeners[iop_num][chan].handler;
  391. offset = IOP_ADDR_RECV_MSG + (chan * IOP_MSG_LEN);
  392. for (i = 0 ; i < IOP_MSG_LEN ; i++, offset++) {
  393. msg->message[i] = iop_readb(iop, offset);
  394. }
  395. iop_writeb(iop, IOP_ADDR_RECV_STATE + chan, IOP_MSG_RCVD);
  396. /* If there is a listener, call it now. Otherwise complete */
  397. /* the message ourselves to avoid possible stalls. */
  398. if (msg->handler) {
  399. (*msg->handler)(msg, regs);
  400. } else {
  401. #ifdef DEBUG_IOP
  402. printk("iop_handle_recv: unclaimed message on iop %d channel %d\n", iop_num, chan);
  403. printk("iop_handle_recv:");
  404. for (i = 0 ; i < IOP_MSG_LEN ; i++) {
  405. printk(" %02X", (uint) msg->message[i]);
  406. }
  407. printk("\n");
  408. #endif
  409. iop_complete_message(msg);
  410. }
  411. }
  412. /*
  413. * Send a message
  414. *
  415. * The message is placed at the end of the send queue. Afterwards if the
  416. * channel is idle we force an immediate send of the next message in the
  417. * queue.
  418. */
  419. int iop_send_message(uint iop_num, uint chan, void *privdata,
  420. uint msg_len, __u8 *msg_data,
  421. void (*handler)(struct iop_msg *, struct pt_regs *))
  422. {
  423. struct iop_msg *msg, *q;
  424. if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return -EINVAL;
  425. if (chan >= NUM_IOP_CHAN) return -EINVAL;
  426. if (msg_len > IOP_MSG_LEN) return -EINVAL;
  427. msg = iop_alloc_msg();
  428. if (!msg) return -ENOMEM;
  429. msg->next = NULL;
  430. msg->status = IOP_MSGSTATUS_WAITING;
  431. msg->iop_num = iop_num;
  432. msg->channel = chan;
  433. msg->caller_priv = privdata;
  434. memcpy(msg->message, msg_data, msg_len);
  435. msg->handler = handler;
  436. if (!(q = iop_send_queue[iop_num][chan])) {
  437. iop_send_queue[iop_num][chan] = msg;
  438. } else {
  439. while (q->next) q = q->next;
  440. q->next = msg;
  441. }
  442. if (iop_readb(iop_base[iop_num],
  443. IOP_ADDR_SEND_STATE + chan) == IOP_MSG_IDLE) {
  444. iop_do_send(msg);
  445. }
  446. return 0;
  447. }
  448. /*
  449. * Upload code to the shared RAM of an IOP.
  450. */
  451. void iop_upload_code(uint iop_num, __u8 *code_start,
  452. uint code_len, __u16 shared_ram_start)
  453. {
  454. if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return;
  455. iop_loadaddr(iop_base[iop_num], shared_ram_start);
  456. while (code_len--) {
  457. iop_base[iop_num]->ram_data = *code_start++;
  458. }
  459. }
  460. /*
  461. * Download code from the shared RAM of an IOP.
  462. */
  463. void iop_download_code(uint iop_num, __u8 *code_start,
  464. uint code_len, __u16 shared_ram_start)
  465. {
  466. if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return;
  467. iop_loadaddr(iop_base[iop_num], shared_ram_start);
  468. while (code_len--) {
  469. *code_start++ = iop_base[iop_num]->ram_data;
  470. }
  471. }
  472. /*
  473. * Compare the code in the shared RAM of an IOP with a copy in system memory
  474. * and return 0 on match or the first nonmatching system memory address on
  475. * failure.
  476. */
  477. __u8 *iop_compare_code(uint iop_num, __u8 *code_start,
  478. uint code_len, __u16 shared_ram_start)
  479. {
  480. if ((iop_num >= NUM_IOPS) || !iop_base[iop_num]) return code_start;
  481. iop_loadaddr(iop_base[iop_num], shared_ram_start);
  482. while (code_len--) {
  483. if (*code_start != iop_base[iop_num]->ram_data) {
  484. return code_start;
  485. }
  486. code_start++;
  487. }
  488. return (__u8 *) 0;
  489. }
  490. /*
  491. * Handle an ISM IOP interrupt
  492. */
  493. irqreturn_t iop_ism_irq(int irq, void *dev_id, struct pt_regs *regs)
  494. {
  495. uint iop_num = (uint) dev_id;
  496. volatile struct mac_iop *iop = iop_base[iop_num];
  497. int i,state;
  498. #ifdef DEBUG_IOP
  499. printk("iop_ism_irq: status = %02X\n", (uint) iop->status_ctrl);
  500. #endif
  501. /* INT0 indicates a state change on an outgoing message channel */
  502. if (iop->status_ctrl & IOP_INT0) {
  503. iop->status_ctrl = IOP_INT0 | IOP_RUN | IOP_AUTOINC;
  504. #ifdef DEBUG_IOP
  505. printk("iop_ism_irq: new status = %02X, send states",
  506. (uint) iop->status_ctrl);
  507. #endif
  508. for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
  509. state = iop_readb(iop, IOP_ADDR_SEND_STATE + i);
  510. #ifdef DEBUG_IOP
  511. printk(" %02X", state);
  512. #endif
  513. if (state == IOP_MSG_COMPLETE) {
  514. iop_handle_send(iop_num, i, regs);
  515. }
  516. }
  517. #ifdef DEBUG_IOP
  518. printk("\n");
  519. #endif
  520. }
  521. if (iop->status_ctrl & IOP_INT1) { /* INT1 for incoming msgs */
  522. iop->status_ctrl = IOP_INT1 | IOP_RUN | IOP_AUTOINC;
  523. #ifdef DEBUG_IOP
  524. printk("iop_ism_irq: new status = %02X, recv states",
  525. (uint) iop->status_ctrl);
  526. #endif
  527. for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
  528. state = iop_readb(iop, IOP_ADDR_RECV_STATE + i);
  529. #ifdef DEBUG_IOP
  530. printk(" %02X", state);
  531. #endif
  532. if (state == IOP_MSG_NEW) {
  533. iop_handle_recv(iop_num, i, regs);
  534. }
  535. }
  536. #ifdef DEBUG_IOP
  537. printk("\n");
  538. #endif
  539. }
  540. return IRQ_HANDLED;
  541. }
  542. #ifdef CONFIG_PROC_FS
  543. char *iop_chan_state(int state)
  544. {
  545. switch(state) {
  546. case IOP_MSG_IDLE : return "idle ";
  547. case IOP_MSG_NEW : return "new ";
  548. case IOP_MSG_RCVD : return "received ";
  549. case IOP_MSG_COMPLETE : return "completed ";
  550. default : return "unknown ";
  551. }
  552. }
  553. int iop_dump_one_iop(char *buf, int iop_num, char *iop_name)
  554. {
  555. int i,len = 0;
  556. volatile struct mac_iop *iop = iop_base[iop_num];
  557. len += sprintf(buf+len, "%s IOP channel states:\n\n", iop_name);
  558. len += sprintf(buf+len, "## send_state recv_state device\n");
  559. len += sprintf(buf+len, "------------------------------------------------\n");
  560. for (i = 0 ; i < NUM_IOP_CHAN ; i++) {
  561. len += sprintf(buf+len, "%2d %10s %10s %s\n", i,
  562. iop_chan_state(iop_readb(iop, IOP_ADDR_SEND_STATE+i)),
  563. iop_chan_state(iop_readb(iop, IOP_ADDR_RECV_STATE+i)),
  564. iop_listeners[iop_num][i].handler?
  565. iop_listeners[iop_num][i].devname : "");
  566. }
  567. len += sprintf(buf+len, "\n");
  568. return len;
  569. }
  570. static int iop_get_proc_info(char *buf, char **start, off_t pos, int count)
  571. {
  572. int len, cnt;
  573. cnt = 0;
  574. len = sprintf(buf, "IOPs detected:\n\n");
  575. if (iop_scc_present) {
  576. len += sprintf(buf+len, "SCC IOP (%p): status %02X\n",
  577. iop_base[IOP_NUM_SCC],
  578. (uint) iop_base[IOP_NUM_SCC]->status_ctrl);
  579. }
  580. if (iop_ism_present) {
  581. len += sprintf(buf+len, "ISM IOP (%p): status %02X\n\n",
  582. iop_base[IOP_NUM_ISM],
  583. (uint) iop_base[IOP_NUM_ISM]->status_ctrl);
  584. }
  585. if (iop_scc_present) {
  586. len += iop_dump_one_iop(buf+len, IOP_NUM_SCC, "SCC");
  587. }
  588. if (iop_ism_present) {
  589. len += iop_dump_one_iop(buf+len, IOP_NUM_ISM, "ISM");
  590. }
  591. if (len >= pos) {
  592. if (!*start) {
  593. *start = buf + pos;
  594. cnt = len - pos;
  595. } else {
  596. cnt += len;
  597. }
  598. }
  599. return (count > cnt) ? cnt : count;
  600. }
  601. #endif /* CONFIG_PROC_FS */