pci_bus_cvlink.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:22k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id$
  2.  *
  3.  * This file is subject to the terms and conditions of the GNU General Public
  4.  * License.  See the file "COPYING" in the main directory of this archive
  5.  * for more details.
  6.  *
  7.  * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  8.  */
  9. #include <linux/config.h>
  10. #include <linux/init.h>
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13. #include <linux/pci_ids.h>
  14. #include <linux/sched.h>
  15. #include <linux/ioport.h>
  16. #include <asm/sn/types.h>
  17. #include <asm/sn/hack.h>
  18. #include <asm/sn/sgi.h>
  19. #include <asm/sn/io.h>
  20. #include <asm/sn/driver.h>
  21. #include <asm/sn/iograph.h>
  22. #include <asm/param.h>
  23. #include <asm/sn/pio.h>
  24. #include <asm/sn/xtalk/xwidget.h>
  25. #include <asm/sn/sn_private.h>
  26. #include <asm/sn/addrs.h>
  27. #include <asm/sn/invent.h>
  28. #include <asm/sn/hcl.h>
  29. #include <asm/sn/hcl_util.h>
  30. #include <asm/sn/intr.h>
  31. #include <asm/sn/xtalk/xtalkaddrs.h>
  32. #include <asm/sn/klconfig.h>
  33. #include <asm/sn/nodepda.h>
  34. #include <asm/sn/pci/pciio.h>
  35. #include <asm/sn/pci/pcibr.h>
  36. #include <asm/sn/pci/pcibr_private.h>
  37. #include <asm/sn/pci/pci_bus_cvlink.h>
  38. #include <asm/sn/simulator.h>
  39. #include <asm/sn/sn_cpuid.h>
  40. extern int bridge_rev_b_data_check_disable;
  41. devfs_handle_t busnum_to_pcibr_vhdl[MAX_PCI_XWIDGET];
  42. nasid_t busnum_to_nid[MAX_PCI_XWIDGET];
  43. void * busnum_to_atedmamaps[MAX_PCI_XWIDGET];
  44. unsigned char num_bridges;
  45. static int done_probing = 0;
  46. static int pci_bus_map_create(devfs_handle_t xtalk);
  47. devfs_handle_t devfn_to_vertex(unsigned char busnum, unsigned int devfn);
  48. #define SN_IOPORTS_UNIT 256
  49. #define MAX_IOPORTS 0xffff
  50. #define MAX_IOPORTS_CHUNKS (MAX_IOPORTS / SN_IOPORTS_UNIT)
  51. struct ioports_to_tlbs_s ioports_to_tlbs[MAX_IOPORTS_CHUNKS];
  52. unsigned long sn_allocate_ioports(unsigned long pci_address);
  53. extern void sn_init_irq_desc(void);
  54. /*
  55.  * pci_bus_cvlink_init() - To be called once during initialization before 
  56.  * SGI IO Infrastructure init is called.
  57.  */
  58. void
  59. pci_bus_cvlink_init(void)
  60. {
  61. memset(busnum_to_pcibr_vhdl, 0x0, sizeof(devfs_handle_t) * MAX_PCI_XWIDGET);
  62. memset(busnum_to_nid, 0x0, sizeof(nasid_t) * MAX_PCI_XWIDGET);
  63. memset(busnum_to_atedmamaps, 0x0, sizeof(void *) * MAX_PCI_XWIDGET);
  64. memset(ioports_to_tlbs, 0x0, sizeof(ioports_to_tlbs));
  65. num_bridges = 0;
  66. }
  67. /*
  68.  * pci_bus_to_vertex() - Given a logical Linux Bus Number returns the associated 
  69.  * pci bus vertex from the SGI IO Infrastructure.
  70.  */
  71. devfs_handle_t
  72. pci_bus_to_vertex(unsigned char busnum)
  73. {
  74. devfs_handle_t pci_bus = NULL;
  75. /*
  76.  * First get the xwidget vertex.
  77.  */
  78. pci_bus = busnum_to_pcibr_vhdl[busnum];
  79. return(pci_bus);
  80. }
  81. /*
  82.  * devfn_to_vertex() - returns the vertex of the device given the bus, slot, 
  83.  * and function numbers.
  84.  */
  85. devfs_handle_t
  86. devfn_to_vertex(unsigned char busnum, unsigned int devfn)
  87. {
  88. int slot = 0;
  89. int func = 0;
  90. char name[16];
  91. devfs_handle_t  pci_bus = NULL;
  92. devfs_handle_t device_vertex = (devfs_handle_t)NULL;
  93. /*
  94.  * Go get the pci bus vertex.
  95.  */
  96. pci_bus = pci_bus_to_vertex(busnum);
  97. if (!pci_bus) {
  98. /*
  99.  * During probing, the Linux pci code invents non-existent
  100.  * bus numbers and pci_dev structures and tries to access
  101.  * them to determine existence. Don't crib during probing.
  102.  */
  103. if (done_probing)
  104. printk("devfn_to_vertex: Invalid bus number %d given.n", busnum);
  105. return(NULL);
  106. }
  107. /*
  108.  * Go get the slot&function vertex.
  109.  * Should call pciio_slot_func_to_name() when ready.
  110.  */
  111. slot = PCI_SLOT(devfn);
  112. func = PCI_FUNC(devfn);
  113. /*
  114.  * For a NON Multi-function card the name of the device looks like:
  115.  * ../pci/1, ../pci/2 ..
  116.  */
  117. if (func == 0) {
  118.          sprintf(name, "%d", slot);
  119. if (hwgraph_traverse(pci_bus, name, &device_vertex) == 
  120. GRAPH_SUCCESS) {
  121. if (device_vertex) {
  122. return(device_vertex);
  123. }
  124. }
  125. }
  126. /*
  127.  * This maybe a multifunction card.  It's names look like:
  128.  * ../pci/1a, ../pci/1b, etc.
  129.  */
  130. sprintf(name, "%d%c", slot, 'a'+func);
  131. if (hwgraph_traverse(pci_bus, name, &device_vertex) != GRAPH_SUCCESS) {
  132. if (!device_vertex) {
  133. return(NULL);
  134. }
  135. }
  136. return(device_vertex);
  137. }
  138. /*
  139.  * For the given device, initialize the addresses for both the Device(x) Flush 
  140.  * Write Buffer register and the Xbow Flush Register for the port the PCI bus 
  141.  * is connected.
  142.  */
  143. static void
  144. set_flush_addresses(struct pci_dev *device_dev, 
  145. struct sn_device_sysdata *device_sysdata)
  146. {
  147. pciio_info_t pciio_info = pciio_info_get(device_sysdata->vhdl);
  148. pciio_slot_t pciio_slot = pciio_info_slot_get(pciio_info);
  149. pcibr_soft_t pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
  150.      bridge_t               *bridge = pcibr_soft->bs_base;
  151. device_sysdata->dma_buf_sync = (volatile unsigned int *) 
  152. &(bridge->b_wr_req_buf[pciio_slot].reg);
  153. device_sysdata->xbow_buf_sync = (volatile unsigned int *)
  154. XBOW_PRIO_LINKREGS_PTR(NODE_SWIN_BASE(get_nasid(), 0), 
  155. pcibr_soft->bs_xid);
  156. #ifdef DEBUG
  157. printk("set_flush_addresses: dma_buf_sync %p xbow_buf_sync %pn", 
  158. device_sysdata->dma_buf_sync, device_sysdata->xbow_buf_sync);
  159. while((volatile unsigned int )*device_sysdata->dma_buf_sync);
  160. while((volatile unsigned int )*device_sysdata->xbow_buf_sync);
  161. #endif
  162. }
  163. /*
  164.  * Most drivers currently do not properly tell the arch specific pci dma
  165.  * interfaces whether they can handle A64. Here is where we privately
  166.  * keep track of this.
  167.  */
  168. static void __init
  169. set_sn_pci64(struct pci_dev *dev)
  170. {
  171. unsigned short vendor = dev->vendor;
  172. unsigned short device = dev->device;
  173. if (vendor == PCI_VENDOR_ID_QLOGIC) {
  174. if ((device == PCI_DEVICE_ID_QLOGIC_ISP2100) ||
  175. (device == PCI_DEVICE_ID_QLOGIC_ISP2200)) {
  176. SET_PCIA64(dev);
  177. return;
  178. }
  179. }
  180. if (vendor == PCI_VENDOR_ID_SGI) {
  181. if (device == PCI_DEVICE_ID_SGI_IOC3) {
  182. SET_PCIA64(dev);
  183. return;
  184. }
  185. }
  186. }
  187. /*
  188.  * sn_allocate_ioports() - This routine provides the allocation and 
  189.  * mappings between Linux style IOPORTs management.
  190.  *
  191.  * For simplicity sake, SN1 will allocate IOPORTs in chunks of 
  192.  * 256bytes .. irrespective of what the card desires.  This may 
  193.  * have to change when we understand how to deal with legacy ioports 
  194.  * which are hardcoded in some drivers e.g. SVGA.
  195.  *
  196.  * Ofcourse, the SN1 IO Infrastructure has no concept of IOPORT numbers.
  197.  * It will remain so.  The IO Infrastructure will continue to map 
  198.  * IO Resource just like IRIX.  When this is done, we map IOPORT 
  199.  * chunks to these resources.  The Linux drivers will see and use real 
  200.  * IOPORT numbers.  The various IOPORT access macros e.g. inb/outb etc. 
  201.  * does the munging of these IOPORT numbers to make a Uncache Virtual 
  202.  * Address.  This address via the tlb entries generates the PCI Address 
  203.  * allocated by the SN1 IO Infrastructure Layer.
  204.  */
  205. static unsigned long sn_ioport_num = 0x1000; /* Reserve room for Legacy stuff */
  206. unsigned long
  207. sn_allocate_ioports(unsigned long pci_address)
  208. {
  209. unsigned long ioport_index;
  210. /*
  211.  * Just some idiot checking ..
  212.  */
  213. if ( sn_ioport_num > 0xffff ) {
  214. printk("sn_allocate_ioports: No more IO PORTS availablen");
  215. return(-1);
  216. }
  217. /*
  218.  * See Section 4.1.1.5 of Intel IA-64 Acrchitecture Software Developer's
  219.  * Manual for details.
  220.  */
  221. ioport_index = sn_ioport_num / SN_IOPORTS_UNIT;
  222. ioports_to_tlbs[ioport_index].p = 1; /* Present Bit */
  223. ioports_to_tlbs[ioport_index].rv_1 = 0; /* 1 Bit */
  224. ioports_to_tlbs[ioport_index].ma = 4; /* Memory Attributes 3 bits*/
  225. ioports_to_tlbs[ioport_index].a = 1; /* Set Data Access Bit Fault 1 Bit*/
  226. ioports_to_tlbs[ioport_index].d = 1; /* Dirty Bit */
  227. ioports_to_tlbs[ioport_index].pl = 0;/* Privilege Level - All levels can R/W*/
  228. ioports_to_tlbs[ioport_index].ar = 3; /* Access Rights - R/W only*/
  229. ioports_to_tlbs[ioport_index].ppn = pci_address >> 12; /* 4K page size */
  230. ioports_to_tlbs[ioport_index].ed = 0; /* Exception Deferral Bit */
  231. ioports_to_tlbs[ioport_index].ig = 0; /* Ignored */
  232. /* printk("sn_allocate_ioports: ioport_index 0x%x ioports_to_tlbs 0x%pn", ioport_index, ioports_to_tlbs[ioport_index]); */
  233. sn_ioport_num += SN_IOPORTS_UNIT;
  234. return(sn_ioport_num - SN_IOPORTS_UNIT);
  235. }
  236. /*
  237.  * sn_pci_fixup() - This routine is called when platform_pci_fixup() is 
  238.  * invoked at the end of pcibios_init() to link the Linux pci 
  239.  * infrastructure to SGI IO Infrasturcture - ia64/kernel/pci.c
  240.  *
  241.  * Other platform specific fixup can also be done here.
  242.  */
  243. void
  244. sn_pci_fixup(int arg)
  245. {
  246. struct list_head *ln;
  247. struct pci_bus *pci_bus = NULL;
  248. struct pci_dev *device_dev = NULL;
  249. struct sn_widget_sysdata *widget_sysdata;
  250. struct sn_device_sysdata *device_sysdata;
  251. #ifdef SN_IOPORTS
  252. unsigned long ioport;
  253. #endif
  254. pciio_intr_t intr_handle;
  255. int cpuid, bit;
  256. devfs_handle_t device_vertex;
  257. pciio_intr_line_t lines;
  258. extern void sn_pci_find_bios(void);
  259. #ifdef CONFIG_IA64_SGI_SN2
  260. extern int numnodes;
  261. int cnode;
  262. #endif /* CONFIG_IA64_SGI_SN2 */
  263. if (arg == 0) {
  264. sn_init_irq_desc();
  265. sn_pci_find_bios();
  266. #ifdef CONFIG_IA64_SGI_SN2
  267. for (cnode = 0; cnode < numnodes; cnode++) {
  268. extern void intr_init_vecblk(nodepda_t *npda, cnodeid_t, int);
  269. intr_init_vecblk(NODEPDA(cnode), cnode, 0);
  270. #endif /* CONFIG_IA64_SGI_SN2 */
  271. return;
  272. }
  273. #if 0
  274. {
  275.         devfs_handle_t  bridge_vhdl = pci_bus_to_vertex(0);
  276.         pcibr_soft_t    pcibr_soft = (pcibr_soft_t) hwgraph_fastinfo_get(bridge_vhdl);
  277. bridge_t        *bridge = pcibr_soft->bs_base;
  278.         printk("pci_fixup_ioc3: Before devreg fixupn");
  279.         printk("pci_fixup_ioc3: Devreg 0 0x%xn", bridge->b_device[0].reg);
  280.         printk("pci_fixup_ioc3: Devreg 1 0x%xn", bridge->b_device[1].reg);
  281.         printk("pci_fixup_ioc3: Devreg 2 0x%xn", bridge->b_device[2].reg);
  282.         printk("pci_fixup_ioc3: Devreg 3 0x%xn", bridge->b_device[3].reg);
  283.         printk("pci_fixup_ioc3: Devreg 4 0x%xn", bridge->b_device[4].reg);
  284.         printk("pci_fixup_ioc3: Devreg 5 0x%xn", bridge->b_device[5].reg);
  285.         printk("pci_fixup_ioc3: Devreg 6 0x%xn", bridge->b_device[6].reg);
  286.         printk("pci_fixup_ioc3: Devreg 7 0x%xn", bridge->b_device[7].reg);
  287. }
  288. #endif
  289. done_probing = 1;
  290. /*
  291.  * Initialize the pci bus vertex in the pci_bus struct.
  292.  */
  293. for( ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  294. pci_bus = pci_bus_b(ln);
  295. widget_sysdata = kmalloc(sizeof(struct sn_widget_sysdata), 
  296. GFP_KERNEL);
  297. widget_sysdata->vhdl = pci_bus_to_vertex(pci_bus->number);
  298. pci_bus->sysdata = (void *)widget_sysdata;
  299. }
  300. /*
  301.    * set the root start and end so that drivers calling check_region()
  302.  * won't see a conflict
  303.  */
  304. #ifdef SN_IOPORTS
  305. ioport_resource.start  = sn_ioport_num;
  306. ioport_resource.end = 0xffff;
  307. #else
  308. #if defined(CONFIG_IA64_SGI_SN1)
  309. if ( IS_RUNNING_ON_SIMULATOR() ) {
  310. /*
  311.  * IDE legacy IO PORTs are supported in Medusa.
  312.  * Just open up IO PORTs from 0 .. ioport_resource.end.
  313.  */
  314. ioport_resource.start = 0;
  315. } else {
  316. /*
  317.  * We do not support Legacy IO PORT numbers.
  318.  */
  319. ioport_resource.start |= IO_SWIZ_BASE | __IA64_UNCACHED_OFFSET;
  320. }
  321. ioport_resource.end |= (HSPEC_SWIZ_BASE-1) | __IA64_UNCACHED_OFFSET;
  322. #else
  323. // Need something here for sn2.... ZXZXZX
  324. #endif
  325. #endif
  326. /*
  327.  * Set the root start and end for Mem Resource.
  328.  */
  329. iomem_resource.start = 0;
  330. iomem_resource.end = 0xffffffffffffffff;
  331. /*
  332.  * Initialize the device vertex in the pci_dev struct.
  333.  */
  334. pci_for_each_dev(device_dev) {
  335. unsigned int irq;
  336. int idx;
  337. u16 cmd;
  338. devfs_handle_t vhdl;
  339. unsigned long size;
  340. extern int bit_pos_to_irq(int);
  341. if (device_dev->vendor == PCI_VENDOR_ID_SGI &&
  342. device_dev->device == PCI_DEVICE_ID_SGI_IOC3) {
  343. extern void pci_fixup_ioc3(struct pci_dev *d);
  344. pci_fixup_ioc3(device_dev);
  345. }
  346. /* Set the device vertex */
  347. device_sysdata = kmalloc(sizeof(struct sn_device_sysdata),
  348. GFP_KERNEL);
  349. device_sysdata->vhdl = devfn_to_vertex(device_dev->bus->number, device_dev->devfn);
  350. device_sysdata->isa64 = 0;
  351. /*
  352.  * Set the xbridge Device(X) Write Buffer Flush and Xbow Flush 
  353.  * register addresses.
  354.  */
  355. (void) set_flush_addresses(device_dev, device_sysdata);
  356. device_dev->sysdata = (void *) device_sysdata;
  357. set_sn_pci64(device_dev);
  358. pci_read_config_word(device_dev, PCI_COMMAND, &cmd);
  359. /*
  360.  * Set the resources address correctly.  The assumption here 
  361.  * is that the addresses in the resource structure has been
  362.  * read from the card and it was set in the card by our
  363.  * Infrastructure ..
  364.  */
  365. vhdl = device_sysdata->vhdl;
  366. for (idx = 0; idx < PCI_ROM_RESOURCE; idx++) {
  367. size = 0;
  368. size = device_dev->resource[idx].end -
  369. device_dev->resource[idx].start;
  370. if (size) {
  371. device_dev->resource[idx].start = (unsigned long)pciio_pio_addr(vhdl, 0, PCIIO_SPACE_WIN(idx), 0, size, 0, PCIIO_BYTE_STREAM);
  372. device_dev->resource[idx].start |= __IA64_UNCACHED_OFFSET;
  373. }
  374. else
  375. continue;
  376. device_dev->resource[idx].end = 
  377. device_dev->resource[idx].start + size;
  378. #ifdef CONFIG_IA64_SGI_SN1
  379. /*
  380.  * Adjust the addresses to go to the SWIZZLE ..
  381.  */
  382. device_dev->resource[idx].start = 
  383. device_dev->resource[idx].start & 0xfffff7ffffffffff;
  384. device_dev->resource[idx].end = 
  385. device_dev->resource[idx].end & 0xfffff7ffffffffff;
  386. #endif
  387. if (device_dev->resource[idx].flags & IORESOURCE_IO) {
  388. cmd |= PCI_COMMAND_IO;
  389. #ifdef SN_IOPORTS
  390. ioport = sn_allocate_ioports(device_dev->resource[idx].start);
  391. if (ioport < 0) {
  392. printk("sn_pci_fixup: PCI Device 0x%x on PCI Bus %d not mapped to IO PORTs .. IO PORTs exhaustedn", device_dev->devfn, device_dev->bus->number);
  393. continue;
  394. }
  395. pciio_config_set(vhdl, (unsigned) PCI_BASE_ADDRESS_0 + (idx * 4), 4, (res + (ioport & 0xfff)));
  396. printk("sn_pci_fixup: ioport number %d mapped to pci address 0x%lxn", ioport, (res + (ioport & 0xfff)));
  397. device_dev->resource[idx].start = ioport;
  398. device_dev->resource[idx].end = ioport + SN_IOPORTS_UNIT;
  399. #endif
  400. }
  401. if (device_dev->resource[idx].flags & IORESOURCE_MEM)
  402. cmd |= PCI_COMMAND_MEMORY;
  403. }
  404. /*
  405.  * Now handle the ROM resource ..
  406.  */
  407. size = device_dev->resource[PCI_ROM_RESOURCE].end -
  408. device_dev->resource[PCI_ROM_RESOURCE].start;
  409. if (size) {
  410. device_dev->resource[PCI_ROM_RESOURCE].start =
  411. (unsigned long) pciio_pio_addr(vhdl, 0, PCIIO_SPACE_ROM, 0, 
  412. size, 0, PCIIO_BYTE_STREAM);
  413. device_dev->resource[PCI_ROM_RESOURCE].start |= __IA64_UNCACHED_OFFSET;
  414. device_dev->resource[PCI_ROM_RESOURCE].end =
  415. device_dev->resource[PCI_ROM_RESOURCE].start + size;
  416. #ifdef CONFIG_IA64_SGI_SN1
  417.                  /*
  418.                    * go through synergy swizzled space
  419.                    */
  420. device_dev->resource[PCI_ROM_RESOURCE].start &= 0xfffff7ffffffffffUL;
  421. device_dev->resource[PCI_ROM_RESOURCE].end   &= 0xfffff7ffffffffffUL;
  422. #endif
  423. }
  424. /*
  425.  * Update the Command Word on the Card.
  426.  */
  427. cmd |= PCI_COMMAND_MASTER; /* If the device doesn't support */
  428.    /* bit gets dropped .. no harm */
  429. pci_write_config_word(device_dev, PCI_COMMAND, cmd);
  430. pci_read_config_byte(device_dev, PCI_INTERRUPT_PIN, (unsigned char *)&lines);
  431. if (device_dev->vendor == PCI_VENDOR_ID_SGI &&
  432. device_dev->device == PCI_DEVICE_ID_SGI_IOC3 ) {
  433. lines = 1;
  434. }
  435.  
  436. device_sysdata = (struct sn_device_sysdata *)device_dev->sysdata;
  437. device_vertex = device_sysdata->vhdl;
  438.  
  439. intr_handle = pciio_intr_alloc(device_vertex, NULL, lines, device_vertex);
  440. bit = intr_handle->pi_irq;
  441. cpuid = intr_handle->pi_cpu;
  442. #ifdef CONFIG_IA64_SGI_SN1
  443. irq = bit_pos_to_irq(bit);
  444. #else /* SN2 */
  445. irq = bit;
  446. #endif
  447. irq = irq + (cpuid << 8);
  448. pciio_intr_connect(intr_handle);
  449. device_dev->irq = irq;
  450. #ifdef ajmtestintr
  451. {
  452. int slot = PCI_SLOT(device_dev->devfn);
  453. static int timer_set = 0;
  454. pcibr_intr_t pcibr_intr = (pcibr_intr_t)intr_handle;
  455. pcibr_soft_t pcibr_soft = pcibr_intr->bi_soft;
  456. extern void intr_test_handle_intr(int, void*, struct pt_regs *);
  457. if (!timer_set) {
  458. intr_test_set_timer();
  459. timer_set = 1;
  460. }
  461. intr_test_register_irq(irq, pcibr_soft, slot);
  462. request_irq(irq, intr_test_handle_intr,0,NULL, NULL);
  463. }
  464. #endif
  465. }
  466. #if 0
  467. {
  468.         devfs_handle_t  bridge_vhdl = pci_bus_to_vertex(0);
  469.         pcibr_soft_t    pcibr_soft = (pcibr_soft_t) hwgraph_fastinfo_get(bridge_vhdl);
  470.         bridge_t        *bridge = pcibr_soft->bs_base;
  471.         printk("pci_fixup_ioc3: Before devreg fixupn");
  472.         printk("pci_fixup_ioc3: Devreg 0 0x%xn", bridge->b_device[0].reg);
  473.         printk("pci_fixup_ioc3: Devreg 1 0x%xn", bridge->b_device[1].reg);
  474.         printk("pci_fixup_ioc3: Devreg 2 0x%xn", bridge->b_device[2].reg);
  475.         printk("pci_fixup_ioc3: Devreg 3 0x%xn", bridge->b_device[3].reg);
  476.         printk("pci_fixup_ioc3: Devreg 4 0x%xn", bridge->b_device[4].reg);
  477.         printk("pci_fixup_ioc3: Devreg 5 0x%xn", bridge->b_device[5].reg);
  478.         printk("pci_fixup_ioc3: Devreg 6 0x%xn", bridge->b_device[6].reg);
  479.         printk("pci_fixup_ioc3: Devreg 7 0x%xn", bridge->b_device[7].reg);
  480. }
  481. printk("testing Big Window: 0xC0000200c0000000 %pn", *( (volatile uint64_t *)0xc0000200a0000000));
  482. printk("testing Big Window: 0xC0000200c0000008 %pn", *( (volatile uint64_t *)0xc0000200a0000008));
  483. #endif
  484. }
  485. /*
  486.  * pci_bus_map_create() - Called by pci_bus_to_hcl_cvlink() to finish the job.
  487.  *
  488.  * Linux PCI Bus numbers are assigned from lowest module_id numbers
  489.  * (rack/slot etc.) starting from HUB_WIDGET_ID_MAX down to 
  490.  * HUB_WIDGET_ID_MIN:
  491.  * widgetnum 15 gets lower Bus Number than widgetnum 14 etc.
  492.  *
  493.  * Given 2 modules 001c01 and 001c02 we get the following mappings:
  494.  * 001c01, widgetnum 15 = Bus number 0
  495.  * 001c01, widgetnum 14 = Bus number 1
  496.  * 001c02, widgetnum 15 = Bus number 3
  497.  * 001c02, widgetnum 14 = Bus number 4
  498.  * etc.
  499.  *
  500.  * The rational for starting Bus Number 0 with Widget number 15 is because 
  501.  * the system boot disks are always connected via Widget 15 Slot 0 of the 
  502.  * I-brick.  Linux creates /dev/sd* devices(naming) strating from Bus Number 0 
  503.  * Therefore, /dev/sda1 will be the first disk, on Widget 15 of the lowest 
  504.  * module id(Master Cnode) of the system.
  505.  *
  506.  */
  507. static int 
  508. pci_bus_map_create(devfs_handle_t xtalk)
  509. {
  510. devfs_handle_t master_node_vertex = NULL;
  511. devfs_handle_t xwidget = NULL;
  512. devfs_handle_t pci_bus = NULL;
  513. hubinfo_t hubinfo = NULL;
  514. xwidgetnum_t widgetnum;
  515. char pathname[128];
  516. graph_error_t rv;
  517. /*
  518.  * Loop throught this vertex and get the Xwidgets ..
  519.  */
  520. for (widgetnum = HUB_WIDGET_ID_MAX; widgetnum >= HUB_WIDGET_ID_MIN; widgetnum--) {
  521. #if 0
  522.         {
  523.                 int pos;
  524.                 char dname[256];
  525.                 pos = devfs_generate_path(xtalk, dname, 256);
  526.                 printk("%s : path= %sn", __FUNCTION__, &dname[pos]);
  527.         }
  528. #endif
  529. sprintf(pathname, "%d", widgetnum);
  530. xwidget = NULL;
  531. /*
  532.  * Example - /hw/module/001c16/Pbrick/xtalk/8 is the xwidget
  533.  *      /hw/module/001c16/Pbrick/xtalk/8/pci/1 is device
  534.  */
  535. rv = hwgraph_traverse(xtalk, pathname, &xwidget);
  536. if ( (rv != GRAPH_SUCCESS) ) {
  537. if (!xwidget)
  538. continue;
  539. }
  540. sprintf(pathname, "%d/"EDGE_LBL_PCI, widgetnum);
  541. pci_bus = NULL;
  542. if (hwgraph_traverse(xtalk, pathname, &pci_bus) != GRAPH_SUCCESS)
  543. if (!pci_bus)
  544. continue;
  545. /*
  546.  * Assign the correct bus number and also the nasid of this 
  547.  * pci Xwidget.
  548.  * 
  549.  * Should not be any race here ...
  550.  */
  551. num_bridges++;
  552. busnum_to_pcibr_vhdl[num_bridges - 1] = pci_bus;
  553. /*
  554.  * Get the master node and from there get the NASID.
  555.  */
  556. master_node_vertex = device_master_get(xwidget);
  557. if (!master_node_vertex) {
  558. printk("WARNING: pci_bus_map_create: Unable to get .master for vertex 0x%pn", (void *)xwidget);
  559. }
  560. hubinfo_get(master_node_vertex, &hubinfo);
  561. if (!hubinfo) {
  562. printk("WARNING: pci_bus_map_create: Unable to get hubinfo for master node vertex 0x%pn", (void *)master_node_vertex);
  563. return(1);
  564. } else {
  565. busnum_to_nid[num_bridges - 1] = hubinfo->h_nasid;
  566. }
  567. /*
  568.  * Pre assign DMA maps needed for 32 Bits Page Map DMA.
  569.  */
  570. busnum_to_atedmamaps[num_bridges - 1] = (void *) kmalloc(
  571. sizeof(struct sn_dma_maps_s) * MAX_ATE_MAPS, GFP_KERNEL);
  572. if (!busnum_to_atedmamaps[num_bridges - 1])
  573. printk("WARNING: pci_bus_map_create: Unable to precreate ATE DMA Maps for busnum %d vertex 0x%pn", num_bridges - 1, (void *)xwidget);
  574. memset(busnum_to_atedmamaps[num_bridges - 1], 0x0, 
  575. sizeof(struct sn_dma_maps_s) * MAX_ATE_MAPS);
  576. }
  577.         return(0);
  578. }
  579. /*
  580.  * pci_bus_to_hcl_cvlink() - This routine is called after SGI IO Infrastructure   
  581.  *      initialization has completed to set up the mappings between Xbridge
  582.  *      and logical pci bus numbers.  We also set up the NASID for each of these
  583.  *      xbridges.
  584.  *
  585.  *      Must be called before pci_init() is invoked.
  586.  */
  587. int
  588. pci_bus_to_hcl_cvlink(void) 
  589. {
  590. devfs_handle_t devfs_hdl = NULL;
  591. devfs_handle_t xtalk = NULL;
  592. int rv = 0;
  593. char name[256];
  594. int master_iobrick;
  595. int i;
  596. /*
  597.  * Iterate throught each xtalk links in the system ..
  598.  * /hw/module/001c01/node/xtalk/ 8|9|10|11|12|13|14|15 
  599.  *
  600.  * /hw/module/001c01/node/xtalk/15 -> /hw/module/001c01/Ibrick/xtalk/15
  601.  *
  602.  * What if it is not pci?
  603.  */
  604. devfs_hdl = hwgraph_path_to_vertex("/dev/hw/module");
  605. /*
  606.  * To provide consistent(not persistent) device naming, we need to start 
  607.  * bus number allocation from the C-Brick with the lowest module id e.g. 001c01 
  608.  * with an attached I-Brick.  Find the master_iobrick.
  609.  */
  610. master_iobrick = -1;
  611. for (i = 0; i < nummodules; i++) {
  612. moduleid_t iobrick_id; 
  613. iobrick_id = iobrick_module_get(&modules[i]->elsc);
  614. if (iobrick_id > 0) { /* Valid module id */
  615. if (MODULE_GET_BTYPE(iobrick_id) == MODULE_IBRICK) {
  616. master_iobrick = i;
  617. break;
  618. }
  619. }
  620. }
  621. /*
  622.  * The master_iobrick gets bus 0 and 1.
  623.  */
  624. if (master_iobrick >= 0) {
  625. memset(name, 0, 256);
  626. format_module_id(name, modules[master_iobrick]->id, MODULE_FORMAT_BRIEF);
  627. strcat(name, "/node/xtalk");
  628. xtalk = NULL;
  629. rv = hwgraph_edge_get(devfs_hdl, name, &xtalk);
  630. pci_bus_map_create(xtalk);
  631. }
  632. /*
  633.  * Now go do the rest of the modules, starting from the C-Brick with the lowest 
  634.  * module id, remembering to skip the master_iobrick, which was done above.
  635.  */
  636. for (i = 0; i < nummodules; i++) {
  637. if (i == master_iobrick) {
  638. continue; /* Did the master_iobrick already. */
  639. }
  640. memset(name, 0, 256);
  641. format_module_id(name, modules[i]->id, MODULE_FORMAT_BRIEF);
  642. strcat(name, "/node/xtalk");
  643. xtalk = NULL;
  644. rv = hwgraph_edge_get(devfs_hdl, name, &xtalk);
  645. pci_bus_map_create(xtalk);
  646. }
  647. return(0);
  648. }