commproc.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * General Purpose functions for the global management of the
  3. * Communication Processor Module.
  4. *
  5. * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com>
  6. * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
  7. *
  8. * In addition to the individual control of the communication
  9. * channels, there are a few functions that globally affect the
  10. * communication processor.
  11. *
  12. * Buffer descriptors must be allocated from the dual ported memory
  13. * space. The allocator for that is here. When the communication
  14. * process is reset, we reclaim the memory available. There is
  15. * currently no deallocator for this memory.
  16. * The amount of space available is platform dependent. On the
  17. * MBX, the EPPC software loads additional microcode into the
  18. * communication processor, and uses some of the DP ram for this
  19. * purpose. Current, the first 512 bytes and the last 256 bytes of
  20. * memory are used. Right now I am conservative and only use the
  21. * memory that can never be used for microcode. If there are
  22. * applications that require more DP ram, we can expand the boundaries
  23. * but then we have to be careful of any downloaded microcode.
  24. *
  25. */
  26. /*
  27. * Michael Leslie <mleslie@lineo.com>
  28. * adapted Dan Malek's ppc8xx drivers to M68360
  29. *
  30. */
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <linux/sched.h>
  34. #include <linux/kernel.h>
  35. #include <linux/param.h>
  36. #include <linux/string.h>
  37. #include <linux/mm.h>
  38. #include <linux/interrupt.h>
  39. #include <asm/irq.h>
  40. #include <asm/m68360.h>
  41. #include <asm/commproc.h>
  42. /* #include <asm/page.h> */
  43. /* #include <asm/pgtable.h> */
  44. extern void *_quicc_base;
  45. extern unsigned int system_clock;
  46. static uint dp_alloc_base; /* Starting offset in DP ram */
  47. static uint dp_alloc_top; /* Max offset + 1 */
  48. #if 0
  49. static void *host_buffer; /* One page of host buffer */
  50. static void *host_end; /* end + 1 */
  51. #endif
  52. /* struct cpm360_t *cpmp; */ /* Pointer to comm processor space */
  53. QUICC *pquicc;
  54. /* QUICC *quicc_dpram; */ /* mleslie - temporary; use extern pquicc elsewhere instead */
  55. /* CPM interrupt vector functions. */
  56. struct cpm_action {
  57. irq_handler_t handler;
  58. void *dev_id;
  59. };
  60. static struct cpm_action cpm_vecs[CPMVEC_NR];
  61. static void cpm_interrupt(int irq, void * dev, struct pt_regs * regs);
  62. static void cpm_error_interrupt(void *);
  63. /* prototypes: */
  64. void cpm_install_handler(int vec, irq_handler_t handler, void *dev_id);
  65. void m360_cpm_reset(void);
  66. void __init m360_cpm_reset()
  67. {
  68. /* pte_t *pte; */
  69. pquicc = (struct quicc *)(_quicc_base); /* initialized in crt0_rXm.S */
  70. /* Perform a CPM reset. */
  71. pquicc->cp_cr = (SOFTWARE_RESET | CMD_FLAG);
  72. /* Wait for CPM to become ready (should be 2 clocks). */
  73. while (pquicc->cp_cr & CMD_FLAG);
  74. /* On the recommendation of the 68360 manual, p. 7-60
  75. * - Set sdma interrupt service mask to 7
  76. * - Set sdma arbitration ID to 4
  77. */
  78. pquicc->sdma_sdcr = 0x0740;
  79. /* Claim the DP memory for our use.
  80. */
  81. dp_alloc_base = CPM_DATAONLY_BASE;
  82. dp_alloc_top = dp_alloc_base + CPM_DATAONLY_SIZE;
  83. /* Set the host page for allocation.
  84. */
  85. /* host_buffer = host_page_addr; */
  86. /* host_end = host_page_addr + PAGE_SIZE; */
  87. /* pte = find_pte(&init_mm, host_page_addr); */
  88. /* pte_val(*pte) |= _PAGE_NO_CACHE; */
  89. /* flush_tlb_page(current->mm->mmap, host_buffer); */
  90. /* Tell everyone where the comm processor resides.
  91. */
  92. /* cpmp = (cpm360_t *)commproc; */
  93. }
  94. /* This is called during init_IRQ. We used to do it above, but this
  95. * was too early since init_IRQ was not yet called.
  96. */
  97. void
  98. cpm_interrupt_init(void)
  99. {
  100. /* Initialize the CPM interrupt controller.
  101. * NOTE THAT pquicc had better have been initialized!
  102. * reference: MC68360UM p. 7-377
  103. */
  104. pquicc->intr_cicr =
  105. (CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1) |
  106. (CPM_INTERRUPT << 13) |
  107. CICR_HP_MASK |
  108. (CPM_VECTOR_BASE << 5) |
  109. CICR_SPS;
  110. /* mask all CPM interrupts from reaching the cpu32 core: */
  111. pquicc->intr_cimr = 0;
  112. /* mles - If I understand correctly, the 360 just pops over to the CPM
  113. * specific vector, obviating the necessity to vector through the IRQ
  114. * whose priority the CPM is set to. This needs a closer look, though.
  115. */
  116. /* Set our interrupt handler with the core CPU. */
  117. /* if (request_irq(CPM_INTERRUPT, cpm_interrupt, 0, "cpm", NULL) != 0) */
  118. /* panic("Could not allocate CPM IRQ!"); */
  119. /* Install our own error handler.
  120. */
  121. /* I think we want to hold off on this one for the moment - mles */
  122. /* cpm_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL); */
  123. /* master CPM interrupt enable */
  124. /* pquicc->intr_cicr |= CICR_IEN; */ /* no such animal for 360 */
  125. }
  126. /* CPM interrupt controller interrupt.
  127. */
  128. static void
  129. cpm_interrupt(int irq, void * dev, struct pt_regs * regs)
  130. {
  131. /* uint vec; */
  132. /* mles: Note that this stuff is currently being performed by
  133. * M68360_do_irq(int vec, struct pt_regs *fp), in ../ints.c */
  134. /* figure out the vector */
  135. /* call that vector's handler */
  136. /* clear the irq's bit in the service register */
  137. #if 0 /* old 860 stuff: */
  138. /* Get the vector by setting the ACK bit and then reading
  139. * the register.
  140. */
  141. ((volatile immap_t *)IMAP_ADDR)->im_cpic.cpic_civr = 1;
  142. vec = ((volatile immap_t *)IMAP_ADDR)->im_cpic.cpic_civr;
  143. vec >>= 11;
  144. if (cpm_vecs[vec].handler != 0)
  145. (*cpm_vecs[vec].handler)(cpm_vecs[vec].dev_id);
  146. else
  147. ((immap_t *)IMAP_ADDR)->im_cpic.cpic_cimr &= ~(1 << vec);
  148. /* After servicing the interrupt, we have to remove the status
  149. * indicator.
  150. */
  151. ((immap_t *)IMAP_ADDR)->im_cpic.cpic_cisr |= (1 << vec);
  152. #endif
  153. }
  154. /* The CPM can generate the error interrupt when there is a race condition
  155. * between generating and masking interrupts. All we have to do is ACK it
  156. * and return. This is a no-op function so we don't need any special
  157. * tests in the interrupt handler.
  158. */
  159. static void
  160. cpm_error_interrupt(void *dev)
  161. {
  162. }
  163. /* Install a CPM interrupt handler.
  164. */
  165. void
  166. cpm_install_handler(int vec, irq_handler_t handler, void *dev_id)
  167. {
  168. request_irq(vec, handler, 0, "timer", dev_id);
  169. /* if (cpm_vecs[vec].handler != 0) */
  170. /* printk(KERN_INFO "CPM interrupt %x replacing %x\n", */
  171. /* (uint)handler, (uint)cpm_vecs[vec].handler); */
  172. /* cpm_vecs[vec].handler = handler; */
  173. /* cpm_vecs[vec].dev_id = dev_id; */
  174. /* ((immap_t *)IMAP_ADDR)->im_cpic.cpic_cimr |= (1 << vec); */
  175. /* pquicc->intr_cimr |= (1 << vec); */
  176. }
  177. /* Free a CPM interrupt handler.
  178. */
  179. void
  180. cpm_free_handler(int vec)
  181. {
  182. cpm_vecs[vec].handler = NULL;
  183. cpm_vecs[vec].dev_id = NULL;
  184. /* ((immap_t *)IMAP_ADDR)->im_cpic.cpic_cimr &= ~(1 << vec); */
  185. pquicc->intr_cimr &= ~(1 << vec);
  186. }
  187. /* Allocate some memory from the dual ported ram. We may want to
  188. * enforce alignment restrictions, but right now everyone is a good
  189. * citizen.
  190. */
  191. uint
  192. m360_cpm_dpalloc(uint size)
  193. {
  194. uint retloc;
  195. if ((dp_alloc_base + size) >= dp_alloc_top)
  196. return(CPM_DP_NOSPACE);
  197. retloc = dp_alloc_base;
  198. dp_alloc_base += size;
  199. return(retloc);
  200. }
  201. #if 0 /* mleslie - for now these are simply kmalloc'd */
  202. /* We also own one page of host buffer space for the allocation of
  203. * UART "fifos" and the like.
  204. */
  205. uint
  206. m360_cpm_hostalloc(uint size)
  207. {
  208. uint retloc;
  209. if ((host_buffer + size) >= host_end)
  210. return(0);
  211. retloc = host_buffer;
  212. host_buffer += size;
  213. return(retloc);
  214. }
  215. #endif
  216. /* Set a baud rate generator. This needs lots of work. There are
  217. * four BRGs, any of which can be wired to any channel.
  218. * The internal baud rate clock is the system clock divided by 16.
  219. * This assumes the baudrate is 16x oversampled by the uart.
  220. */
  221. /* #define BRG_INT_CLK (((bd_t *)__res)->bi_intfreq * 1000000) */
  222. #define BRG_INT_CLK system_clock
  223. #define BRG_UART_CLK (BRG_INT_CLK/16)
  224. void
  225. m360_cpm_setbrg(uint brg, uint rate)
  226. {
  227. volatile uint *bp;
  228. /* This is good enough to get SMCs running.....
  229. */
  230. /* bp = (uint *)&cpmp->cp_brgc1; */
  231. bp = (volatile uint *)(&pquicc->brgc[0].l);
  232. bp += brg;
  233. *bp = ((BRG_UART_CLK / rate - 1) << 1) | CPM_BRG_EN;
  234. }
  235. /*
  236. * Local variables:
  237. * c-indent-level: 4
  238. * c-basic-offset: 4
  239. * tab-width: 4
  240. * End:
  241. */