pci_sun4v.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* pci_sun4v.c: SUN4V specific PCI controller support.
  2. *
  3. * Copyright (C) 2006 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/pci.h>
  8. #include <linux/init.h>
  9. #include <linux/slab.h>
  10. #include <linux/interrupt.h>
  11. #include <asm/pbm.h>
  12. #include <asm/iommu.h>
  13. #include <asm/irq.h>
  14. #include <asm/upa.h>
  15. #include <asm/pstate.h>
  16. #include <asm/oplib.h>
  17. #include <asm/hypervisor.h>
  18. #include "pci_impl.h"
  19. #include "iommu_common.h"
  20. #include "pci_sun4v.h"
  21. static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp)
  22. {
  23. return NULL;
  24. }
  25. static void pci_4v_free_consistent(struct pci_dev *pdev, size_t size, void *cpu, dma_addr_t dvma)
  26. {
  27. }
  28. static dma_addr_t pci_4v_map_single(struct pci_dev *pdev, void *ptr, size_t sz, int direction)
  29. {
  30. return 0;
  31. }
  32. static void pci_4v_unmap_single(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction)
  33. {
  34. }
  35. static int pci_4v_map_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
  36. {
  37. return nelems;
  38. }
  39. static void pci_4v_unmap_sg(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
  40. {
  41. }
  42. static void pci_4v_dma_sync_single_for_cpu(struct pci_dev *pdev, dma_addr_t bus_addr, size_t sz, int direction)
  43. {
  44. }
  45. static void pci_4v_dma_sync_sg_for_cpu(struct pci_dev *pdev, struct scatterlist *sglist, int nelems, int direction)
  46. {
  47. }
  48. struct pci_iommu_ops pci_sun4v_iommu_ops = {
  49. .alloc_consistent = pci_4v_alloc_consistent,
  50. .free_consistent = pci_4v_free_consistent,
  51. .map_single = pci_4v_map_single,
  52. .unmap_single = pci_4v_unmap_single,
  53. .map_sg = pci_4v_map_sg,
  54. .unmap_sg = pci_4v_unmap_sg,
  55. .dma_sync_single_for_cpu = pci_4v_dma_sync_single_for_cpu,
  56. .dma_sync_sg_for_cpu = pci_4v_dma_sync_sg_for_cpu,
  57. };
  58. /* SUN4V PCI configuration space accessors. */
  59. static int pci_sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  60. int where, int size, u32 *value)
  61. {
  62. /* XXX Implement me! XXX */
  63. return 0;
  64. }
  65. static int pci_sun4v_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  66. int where, int size, u32 value)
  67. {
  68. /* XXX Implement me! XXX */
  69. return 0;
  70. }
  71. static struct pci_ops pci_sun4v_ops = {
  72. .read = pci_sun4v_read_pci_cfg,
  73. .write = pci_sun4v_write_pci_cfg,
  74. };
  75. static void pci_sun4v_scan_bus(struct pci_controller_info *p)
  76. {
  77. /* XXX Implement me! XXX */
  78. }
  79. static unsigned int pci_sun4v_irq_build(struct pci_pbm_info *pbm,
  80. struct pci_dev *pdev,
  81. unsigned int ino)
  82. {
  83. /* XXX Implement me! XXX */
  84. return 0;
  85. }
  86. /* XXX correct? XXX */
  87. static void pci_sun4v_base_address_update(struct pci_dev *pdev, int resource)
  88. {
  89. struct pcidev_cookie *pcp = pdev->sysdata;
  90. struct pci_pbm_info *pbm = pcp->pbm;
  91. struct resource *res, *root;
  92. u32 reg;
  93. int where, size, is_64bit;
  94. res = &pdev->resource[resource];
  95. if (resource < 6) {
  96. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  97. } else if (resource == PCI_ROM_RESOURCE) {
  98. where = pdev->rom_base_reg;
  99. } else {
  100. /* Somebody might have asked allocation of a non-standard resource */
  101. return;
  102. }
  103. is_64bit = 0;
  104. if (res->flags & IORESOURCE_IO)
  105. root = &pbm->io_space;
  106. else {
  107. root = &pbm->mem_space;
  108. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  109. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  110. is_64bit = 1;
  111. }
  112. size = res->end - res->start;
  113. pci_read_config_dword(pdev, where, &reg);
  114. reg = ((reg & size) |
  115. (((u32)(res->start - root->start)) & ~size));
  116. if (resource == PCI_ROM_RESOURCE) {
  117. reg |= PCI_ROM_ADDRESS_ENABLE;
  118. res->flags |= IORESOURCE_ROM_ENABLE;
  119. }
  120. pci_write_config_dword(pdev, where, reg);
  121. /* This knows that the upper 32-bits of the address
  122. * must be zero. Our PCI common layer enforces this.
  123. */
  124. if (is_64bit)
  125. pci_write_config_dword(pdev, where + 4, 0);
  126. }
  127. /* XXX correct? XXX */
  128. static void pci_sun4v_resource_adjust(struct pci_dev *pdev,
  129. struct resource *res,
  130. struct resource *root)
  131. {
  132. res->start += root->start;
  133. res->end += root->start;
  134. }
  135. /* Use ranges property to determine where PCI MEM, I/O, and Config
  136. * space are for this PCI bus module.
  137. */
  138. static void pci_sun4v_determine_mem_io_space(struct pci_pbm_info *pbm)
  139. {
  140. int i, saw_cfg, saw_mem, saw_io;
  141. saw_cfg = saw_mem = saw_io = 0;
  142. for (i = 0; i < pbm->num_pbm_ranges; i++) {
  143. struct linux_prom_pci_ranges *pr = &pbm->pbm_ranges[i];
  144. unsigned long a;
  145. int type;
  146. type = (pr->child_phys_hi >> 24) & 0x3;
  147. a = (((unsigned long)pr->parent_phys_hi << 32UL) |
  148. ((unsigned long)pr->parent_phys_lo << 0UL));
  149. switch (type) {
  150. case 0:
  151. /* PCI config space, 16MB */
  152. pbm->config_space = a;
  153. saw_cfg = 1;
  154. break;
  155. case 1:
  156. /* 16-bit IO space, 16MB */
  157. pbm->io_space.start = a;
  158. pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
  159. pbm->io_space.flags = IORESOURCE_IO;
  160. saw_io = 1;
  161. break;
  162. case 2:
  163. /* 32-bit MEM space, 2GB */
  164. pbm->mem_space.start = a;
  165. pbm->mem_space.end = a + (0x80000000UL - 1UL);
  166. pbm->mem_space.flags = IORESOURCE_MEM;
  167. saw_mem = 1;
  168. break;
  169. default:
  170. break;
  171. };
  172. }
  173. if (!saw_cfg || !saw_io || !saw_mem) {
  174. prom_printf("%s: Fatal error, missing %s PBM range.\n",
  175. pbm->name,
  176. ((!saw_cfg ?
  177. "CFG" :
  178. (!saw_io ?
  179. "IO" : "MEM"))));
  180. prom_halt();
  181. }
  182. printk("%s: PCI CFG[%lx] IO[%lx] MEM[%lx]\n",
  183. pbm->name,
  184. pbm->config_space,
  185. pbm->io_space.start,
  186. pbm->mem_space.start);
  187. }
  188. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  189. struct pci_pbm_info *pbm)
  190. {
  191. pbm->io_space.name = pbm->mem_space.name = pbm->name;
  192. request_resource(&ioport_resource, &pbm->io_space);
  193. request_resource(&iomem_resource, &pbm->mem_space);
  194. pci_register_legacy_regions(&pbm->io_space,
  195. &pbm->mem_space);
  196. }
  197. static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
  198. {
  199. /* XXX Implement me! XXX */
  200. }
  201. static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node)
  202. {
  203. struct pci_pbm_info *pbm;
  204. struct linux_prom64_registers regs;
  205. unsigned int busrange[2];
  206. int err;
  207. /* XXX */
  208. pbm = &p->pbm_A;
  209. pbm->parent = p;
  210. pbm->prom_node = prom_node;
  211. pbm->pci_first_slot = 1;
  212. prom_getproperty(prom_node, "reg", (char *)&regs, sizeof(regs));
  213. pbm->devhandle = (regs.phys_addr >> 32UL) & 0x0fffffff;
  214. sprintf(pbm->name, "SUN4V-PCI%d PBM%c",
  215. p->index, (pbm == &p->pbm_A ? 'A' : 'B'));
  216. printk("%s: devhandle[%x]\n", pbm->name, pbm->devhandle);
  217. prom_getstring(prom_node, "name",
  218. pbm->prom_name, sizeof(pbm->prom_name));
  219. err = prom_getproperty(prom_node, "ranges",
  220. (char *) pbm->pbm_ranges,
  221. sizeof(pbm->pbm_ranges));
  222. if (err == 0 || err == -1) {
  223. prom_printf("%s: Fatal error, no ranges property.\n",
  224. pbm->name);
  225. prom_halt();
  226. }
  227. pbm->num_pbm_ranges =
  228. (err / sizeof(struct linux_prom_pci_ranges));
  229. pci_sun4v_determine_mem_io_space(pbm);
  230. pbm_register_toplevel_resources(p, pbm);
  231. err = prom_getproperty(prom_node, "interrupt-map",
  232. (char *)pbm->pbm_intmap,
  233. sizeof(pbm->pbm_intmap));
  234. if (err != -1) {
  235. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  236. err = prom_getproperty(prom_node, "interrupt-map-mask",
  237. (char *)&pbm->pbm_intmask,
  238. sizeof(pbm->pbm_intmask));
  239. if (err == -1) {
  240. prom_printf("%s: Fatal error, no "
  241. "interrupt-map-mask.\n", pbm->name);
  242. prom_halt();
  243. }
  244. } else {
  245. pbm->num_pbm_intmap = 0;
  246. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  247. }
  248. err = prom_getproperty(prom_node, "bus-range",
  249. (char *)&busrange[0],
  250. sizeof(busrange));
  251. if (err == 0 || err == -1) {
  252. prom_printf("%s: Fatal error, no bus-range.\n", pbm->name);
  253. prom_halt();
  254. }
  255. pbm->pci_first_busno = busrange[0];
  256. pbm->pci_last_busno = busrange[1];
  257. pci_sun4v_iommu_init(pbm);
  258. }
  259. void sun4v_pci_init(int node, char *model_name)
  260. {
  261. struct pci_controller_info *p;
  262. struct pci_iommu *iommu;
  263. p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  264. if (!p) {
  265. prom_printf("SUN4V_PCI: Fatal memory allocation error.\n");
  266. prom_halt();
  267. }
  268. memset(p, 0, sizeof(*p));
  269. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  270. if (!iommu) {
  271. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  272. prom_halt();
  273. }
  274. memset(iommu, 0, sizeof(*iommu));
  275. p->pbm_A.iommu = iommu;
  276. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  277. if (!iommu) {
  278. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  279. prom_halt();
  280. }
  281. memset(iommu, 0, sizeof(*iommu));
  282. p->pbm_B.iommu = iommu;
  283. p->next = pci_controller_root;
  284. pci_controller_root = p;
  285. p->index = pci_num_controllers++;
  286. p->pbms_same_domain = 0;
  287. p->scan_bus = pci_sun4v_scan_bus;
  288. p->irq_build = pci_sun4v_irq_build;
  289. p->base_address_update = pci_sun4v_base_address_update;
  290. p->resource_adjust = pci_sun4v_resource_adjust;
  291. p->pci_ops = &pci_sun4v_ops;
  292. /* Like PSYCHO and SCHIZO we have a 2GB aligned area
  293. * for memory space.
  294. */
  295. pci_memspace_mask = 0x7fffffffUL;
  296. pci_sun4v_pbm_init(p, node);
  297. prom_printf("sun4v_pci_init: Implement me.\n");
  298. prom_halt();
  299. }