memoryCall.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * linux/arch/alpha/kernel/core_marvel.c
  3. *
  4. * Code common to all Marvel based systems.
  5. */
  6. #define __EXTERN_INLINE inline
  7. #include <asm/io.h>
  8. #include <asm/core_marvel.h>
  9. #undef __EXTERN_INLINE
  10. #include <linux/types.h>
  11. #include <linux/pci.h>
  12. #include <linux/sched.h>
  13. #include <linux/init.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/mc146818rtc.h>
  16. #include <linux/rtc.h>
  17. #include <linux/module.h>
  18. #include <linux/bootmem.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/smp.h>
  21. #include <asm/gct.h>
  22. #include <asm/pgalloc.h>
  23. #include <asm/tlbflush.h>
  24. #include <asm/rtc.h>
  25. #include <asm/vga.h>
  26. #include "proto.h"
  27. #include "pci_impl.h"
  28. /*
  29. * Debug helpers
  30. */
  31. #define DEBUG_CONFIG 0
  32. #if DEBUG_CONFIG
  33. # define DBG_CFG(args) printk args
  34. #else
  35. # define DBG_CFG(args)
  36. #endif
  37. /*
  38. * Private data
  39. */
  40. static struct io7 *io7_head = NULL;
  41. /*
  42. * Helper functions
  43. */
  44. static unsigned long __attribute__ ((unused))
  45. read_ev7_csr(int pe, unsigned long offset)
  46. {
  47. ev7_csr *ev7csr = EV7_CSR_KERN(pe, offset);
  48. unsigned long q;
  49. mb();
  50. q = ev7csr->csr;
  51. mb();
  52. return q;
  53. }
  54. static void __attribute__ ((unused))
  55. write_ev7_csr(int pe, unsigned long offset, unsigned long q)
  56. {
  57. ev7_csr *ev7csr = EV7_CSR_KERN(pe, offset);
  58. mb();
  59. ev7csr->csr = q;
  60. mb();
  61. }
  62. static char * __init
  63. mk_resource_name(int pe, int port, char *str)
  64. {
  65. char tmp[80];
  66. char *name;
  67. sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port);
  68. name = alloc_bootmem(strlen(tmp) + 1);
  69. strcpy(name, tmp);
  70. return name;
  71. }
  72. inline struct io7 *
  73. marvel_next_io7(struct io7 *prev)
  74. {
  75. return (prev ? prev->next : io7_head);
  76. }
  77. struct io7 *
  78. marvel_find_io7(int pe)
  79. {
  80. struct io7 *io7;
  81. for (io7 = io7_head; io7 && io7->pe != pe; io7 = io7->next)
  82. continue;
  83. return io7;
  84. }
  85. static struct io7 * __init
  86. alloc_io7(unsigned int pe)
  87. {
  88. struct io7 *io7;
  89. struct io7 *insp;
  90. int h;
  91. if (marvel_find_io7(pe)) {
  92. printk(KERN_WARNING "IO7 at PE %d already allocated!\n", pe);
  93. return NULL;
  94. }
  95. io7 = alloc_bootmem(sizeof(*io7));
  96. io7->pe = pe;
  97. spin_lock_init(&io7->irq_lock);
  98. for (h = 0; h < 4; h++) {
  99. io7->ports[h].io7 = io7;
  100. io7->ports[h].port = h;
  101. io7->ports[h].enabled = 0; /* default to disabled */
  102. }
  103. /*
  104. * Insert in pe sorted order.
  105. */
  106. if (NULL == io7_head) /* empty list */
  107. io7_head = io7;
  108. else if (io7_head->pe > io7->pe) { /* insert at head */
  109. io7->next = io7_head;
  110. io7_head = io7;
  111. } else { /* insert at position */
  112. for (insp = io7_head; insp; insp = insp->next) {
  113. if (insp->pe == io7->pe) {
  114. printk(KERN_ERR "Too many IO7s at PE %d\n",
  115. io7->pe);
  116. return NULL;
  117. }
  118. if (NULL == insp->next ||
  119. insp->next->pe > io7->pe) { /* insert here */
  120. io7->next = insp->next;
  121. insp->next = io7;
  122. break;
  123. }
  124. }
  125. if (NULL == insp) { /* couldn't insert ?!? */
  126. printk(KERN_WARNING "Failed to insert IO7 at PE %d "
  127. " - adding at head of list\n", io7->pe);
  128. io7->next = io7_head;
  129. io7_head = io7;
  130. }
  131. }
  132. return io7;
  133. }
  134. void
  135. io7_clear_errors(struct io7 *io7)
  136. {
  137. io7_port7_csrs *p7csrs;
  138. io7_ioport_csrs *csrs;
  139. int port;
  140. /*
  141. * First the IO ports.
  142. */
  143. for (port = 0; port < 4; port++) {
  144. csrs = IO7_CSRS_KERN(io7->pe, port);
  145. csrs->POx_ERR_SUM.csr = -1UL;
  146. csrs->POx_TLB_ERR.csr = -1UL;
  147. csrs->POx_SPL_COMPLT.csr = -1UL;
  148. csrs->POx_TRANS_SUM.csr = -1UL;
  149. }
  150. /*
  151. * Then the common ones.
  152. */
  153. p7csrs = IO7_PORT7_CSRS_KERN(io7->pe);
  154. p7csrs->PO7_ERROR_SUM.csr = -1UL;
  155. p7csrs->PO7_UNCRR_SYM.csr = -1UL;
  156. p7csrs->PO7_CRRCT_SYM.csr = -1UL;
  157. }
  158. /*
  159. * IO7 PCI, PCI/X, AGP configuration.
  160. */
  161. static void __init
  162. io7_init_hose(struct io7 *io7, int port)
  163. {
  164. static int hose_index = 0;
  165. struct pci_controller *hose = alloc_pci_controller();
  166. struct io7_port *io7_port = &io7->ports[port];
  167. io7_ioport_csrs *csrs = IO7_CSRS_KERN(io7->pe, port);
  168. int i;
  169. hose->index = hose_index++; /* arbitrary */
  170. /*
  171. * We don't have an isa or legacy hose, but glibc expects to be
  172. * able to use the bus == 0 / dev == 0 form of the iobase syscall
  173. * to determine information about the i/o system. Since XFree86
  174. * relies on glibc's determination to tell whether or not to use
  175. * sparse access, we need to point the pci_isa_hose at a real hose
  176. * so at least that determination is correct.
  177. */
  178. if (hose->index == 0)
  179. pci_isa_hose = hose;
  180. io7_port->csrs = csrs;
  181. io7_port->hose = hose;
  182. hose->sysdata = io7_port;
  183. hose->io_space = alloc_resource();
  184. hose->mem_space = alloc_resource();
  185. /*
  186. * Base addresses for userland consumption. Since these are going
  187. * to be mapped, they are pure physical addresses.
  188. */
  189. hose->sparse_mem_base = hose->sparse_io_base = 0;
  190. hose->dense_mem_base = IO7_MEM_PHYS(io7->pe, port);
  191. hose->dense_io_base = IO7_IO_PHYS(io7->pe, port);
  192. /*
  193. * Base addresses and resource ranges for kernel consumption.
  194. */
  195. hose->config_space_base = (unsigned long)IO7_CONF_KERN(io7->pe, port);
  196. hose->io_space->start = (unsigned long)IO7_IO_KERN(io7->pe, port);
  197. hose->io_space->end = hose->io_space->start + IO7_IO_SPACE - 1;
  198. hose->io_space->name = mk_resource_name(io7->pe, port, "IO");
  199. hose->io_space->flags = IORESOURCE_IO;
  200. hose->mem_space->start = (unsigned long)IO7_MEM_KERN(io7->pe, port);
  201. hose->mem_space->end = hose->mem_space->start + IO7_MEM_SPACE - 1;
  202. hose->mem_space->name = mk_resource_name(io7->pe, port, "MEM");
  203. hose->mem_space->flags = IORESOURCE_MEM;
  204. if (request_resource(&ioport_resource, hose->io_space) < 0)
  205. printk(KERN_ERR "Failed to request IO on hose %d\n",
  206. hose->index);
  207. if (request_resource(&iomem_resource, hose->mem_space) < 0)
  208. printk(KERN_ERR "Failed to request MEM on hose %d\n",
  209. hose->index);
  210. /*
  211. * Save the existing DMA window settings for later restoration.
  212. */
  213. for (i = 0; i < 4; i++) {
  214. io7_port->saved_wbase[i] = csrs->POx_WBASE[i].csr;
  215. io7_port->saved_wmask[i] = csrs->POx_WMASK[i].csr;
  216. io7_port->saved_tbase[i] = csrs->POx_TBASE[i].csr;
  217. }
  218. /*
  219. * Set up the PCI to main memory translation windows.
  220. *
  221. * Window 0 is scatter-gather 8MB at 8MB
  222. * Window 1 is direct access 1GB at 2GB
  223. * Window 2 is scatter-gather (up-to) 1GB at 3GB
  224. * Window 3 is disabled
  225. */
  226. /*
  227. * TBIA before modifying windows.
  228. */
  229. marvel_pci_tbi(hose, 0, -1);
  230. /*
  231. * Set up window 0 for scatter-gather 8MB at 8MB.
  232. */
  233. hose->sg_isa = iommu_arena_new_node(marvel_cpuid_to_nid(io7->pe),
  234. hose, 0x00800000, 0x00800000, 0);
  235. hose->sg_isa->align_entry = 8; /* cache line boundary */
  236. csrs->POx_WBASE[0].csr =
  237. hose->sg_isa->dma_base | wbase_m_ena | wbase_m_sg;
  238. csrs->POx_WMASK[0].csr = (hose->sg_isa->size - 1) & wbase_m_addr;
  239. csrs->POx_TBASE[0].csr = virt_to_phys(hose->sg_isa->ptes);
  240. /*
  241. * Set up window 1 for direct-mapped 1GB at 2GB.
  242. */
  243. csrs->POx_WBASE[1].csr = __direct_map_base | wbase_m_ena;
  244. csrs->POx_WMASK[1].csr = (__direct_map_size - 1) & wbase_m_addr;
  245. csrs->POx_TBASE[1].csr = 0;
  246. /*
  247. * Set up window 2 for scatter-gather (up-to) 1GB at 3GB.
  248. */
  249. hose->sg_pci = iommu_arena_new_node(marvel_cpuid_to_nid(io7->pe),
  250. hose, 0xc0000000, 0x40000000, 0);
  251. hose->sg_pci->align_entry = 8; /* cache line boundary */
  252. csrs->POx_WBASE[2].csr =
  253. hose->sg_pci->dma_base | wbase_m_ena | wbase_m_sg;
  254. csrs->POx_WMASK[2].csr = (hose->sg_pci->size - 1) & wbase_m_addr;
  255. csrs->POx_TBASE[2].csr = virt_to_phys(hose->sg_pci->ptes);
  256. /*
  257. * Disable window 3.
  258. */
  259. csrs->POx_WBASE[3].csr = 0;
  260. /*
  261. * Make sure that the AGP Monster Window is disabled.
  262. */
  263. csrs->POx_CTRL.csr &= ~(1UL << 61);
  264. #if 1
  265. printk("FIXME: disabling master aborts\n");
  266. csrs->POx_MSK_HEI.csr &= ~(3UL << 14);
  267. #endif
  268. /*
  269. * TBIA after modifying windows.
  270. */
  271. marvel_pci_tbi(hose, 0, -1);
  272. }
  273. static void __init
  274. marvel_init_io7(struct io7 *io7)
  275. {
  276. int i;
  277. printk("Initializing IO7 at PID %d\n", io7->pe);
  278. /*
  279. * Get the Port 7 CSR pointer.
  280. */
  281. io7->csrs = IO7_PORT7_CSRS_KERN(io7->pe);