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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * pSeries_pci.c
  3.  *
  4.  * pSeries_pcibios_init(void)opyright (C) 2001 Dave Engebretsen, IBM Corporation
  5.  *
  6.  * pSeries specific routines for PCI.
  7.  * 
  8.  * Based on code from pci.c and chrp_pci.c
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *    
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  * 
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  23.  */
  24. #include <linux/kernel.h>
  25. #include <linux/pci.h>
  26. #include <linux/delay.h>
  27. #include <linux/string.h>
  28. #include <linux/init.h>
  29. #include <linux/bootmem.h>
  30. #include <asm/io.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/irq.h>
  33. #include <asm/prom.h>
  34. #include <asm/machdep.h>
  35. #include <asm/init.h>
  36. #include <asm/pci-bridge.h>
  37. #include <asm/ppcdebug.h>
  38. #include <asm/naca.h>
  39. #include <asm/pci_dma.h>
  40. #include <asm/eeh.h>
  41. #include "xics.h"
  42. #include "open_pic.h"
  43. #include "pci.h"
  44. extern struct device_node *allnodes;
  45. /*******************************************************************
  46.  * Forward declares of prototypes. 
  47.  *******************************************************************/
  48. unsigned long find_and_init_phbs(void);
  49. struct pci_controller* alloc_phb(struct device_node *dev, char *model, unsigned int addr_size_words) ;
  50. void pSeries_pcibios_fixup(void);
  51. static int rtas_fake_read(struct device_node *dn, int offset, int nbytes, unsigned long *returnval);
  52. /* RTAS tokens */
  53. static int read_pci_config;
  54. static int write_pci_config;
  55. static int ibm_read_pci_config;
  56. static int ibm_write_pci_config;
  57. static int s7a_workaround;
  58. /******************************************************************************
  59.  *
  60.  * pSeries I/O Operations to access the PCI configuration space.
  61.  *
  62.  *****************************************************************************/
  63. #define RTAS_PCI_READ_OP(size, type, nbytes) 
  64. int __chrp 
  65. rtas_read_config_##size(struct device_node *dn, int offset, type val) {  
  66. unsigned long returnval = ~0L; 
  67. unsigned long buid; 
  68. unsigned int addr; 
  69. int ret; 
  70.  
  71. if (dn == NULL) { 
  72. ret = -2; 
  73. } else { 
  74. addr = (dn->busno << 16) | (dn->devfn << 8) | offset; 
  75. buid = dn->phb->buid; 
  76. if (buid) { 
  77. ret = rtas_call(ibm_read_pci_config, 4, 2, &returnval, addr, buid >> 32, buid & 0xffffffff, nbytes); 
  78.                         if (ret < 0 || (returnval == 0xffffffff)) 
  79.                                ret = rtas_fake_read(dn, offset, nbytes, &returnval); 
  80. } else { 
  81. ret = rtas_call(read_pci_config, 2, 2, &returnval, addr, nbytes); 
  82. *val = returnval; 
  83. return ret; 
  84. int __chrp 
  85. rtas_pci_read_config_##size(struct pci_dev *dev, int offset, type val) {  
  86.         struct device_node *dn = pci_device_to_OF_node(dev); 
  87. int ret = rtas_read_config_##size(dn, offset, val); 
  88.         /* udbg_printf("read bus=%x, devfn=%x, ret=%d phb=%lx, dn=%lxn", dev->bus->number, dev->devfn, ret, dn ? dn->phb : 0, dn); */ 
  89.         return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL; 
  90. }
  91. #define RTAS_PCI_WRITE_OP(size, type, nbytes) 
  92. int __chrp 
  93. rtas_write_config_##size(struct device_node *dn, int offset, type val) { 
  94. unsigned long buid; 
  95. unsigned int addr; 
  96. int ret; 
  97.  
  98. if (dn == NULL) { 
  99. ret = -2; 
  100. } else { 
  101. buid = dn->phb->buid; 
  102. addr = (dn->busno << 16) | (dn->devfn << 8) | offset; 
  103. if (buid) { 
  104. ret = rtas_call(ibm_write_pci_config, 5, 1, NULL, addr, buid >> 32, buid & 0xffffffff, nbytes, (ulong) val); 
  105. } else { 
  106. ret = rtas_call(write_pci_config, 3, 1, NULL, addr, nbytes, (ulong)val); 
  107. return ret; 
  108. int __chrp 
  109. rtas_pci_write_config_##size(struct pci_dev *dev, int offset, type val) { 
  110. struct device_node*  dn = pci_device_to_OF_node(dev); 
  111. int  ret = rtas_write_config_##size(dn, offset, val); 
  112. /* udbg_printf("write bus=%x, devfn=%x, ret=%d phb=%lx, dn=%lxn", dev->bus->number, dev->devfn, ret, dn ? dn->phb : 0, dn); */ 
  113. return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL; 
  114. }
  115. RTAS_PCI_READ_OP(byte, u8 *, 1)
  116. RTAS_PCI_READ_OP(word, u16 *, 2)
  117. RTAS_PCI_READ_OP(dword, u32 *, 4)
  118. RTAS_PCI_WRITE_OP(byte, u8, 1)
  119. RTAS_PCI_WRITE_OP(word, u16, 2)
  120. RTAS_PCI_WRITE_OP(dword, u32, 4)
  121. struct pci_ops rtas_pci_ops = {
  122. rtas_pci_read_config_byte,
  123. rtas_pci_read_config_word,
  124. rtas_pci_read_config_dword,
  125. rtas_pci_write_config_byte,
  126.   rtas_pci_write_config_word,
  127. rtas_pci_write_config_dword,
  128. };
  129. /*
  130.  * Handle the case where rtas refuses to do a pci config read.
  131.  * This currently only happens with some PHBs in which case we totally fake
  132.  * out the values (and call it a speedwagaon -- something we could look up
  133.  * in the device tree).
  134.  */
  135. static int
  136. rtas_fake_read(struct device_node *dn, int offset, int nbytes, unsigned long *returnval)
  137. {
  138. char *device_type = (char *)get_property(dn, "device_type", 0);
  139. u32 *class_code = (u32 *)get_property(dn, "class-code", 0);
  140. *returnval = ~0; /* float by default */
  141. /* udbg_printf("rtas_fake_read dn=%p, offset=0x%02x, nbytes=%d, device_type=%sn", dn, offset, nbytes, device_type ? device_type : "<none>"); */
  142. if (device_type && strcmp(device_type, "pci") != 0)
  143. return -3; /* Not a phb or bridge */
  144. /* NOTE: class_code != NULL => EADS pci bridge.  Else a PHB */
  145. if (nbytes == 1) {
  146. if (offset == PCI_HEADER_TYPE)
  147. *returnval = 0x80; /* multifunction */
  148. else if (offset == PCI_INTERRUPT_PIN || offset == PCI_INTERRUPT_LINE)
  149. *returnval = 0;
  150. } else if (nbytes == 2) {
  151. if (offset == PCI_SUBSYSTEM_VENDOR_ID || offset == PCI_SUBSYSTEM_ID)
  152. *returnval = 0;
  153. else if (offset == PCI_COMMAND)
  154. *returnval = PCI_COMMAND_PARITY|PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY;
  155. } else if (nbytes == 4) {
  156. if (offset == PCI_VENDOR_ID)
  157. *returnval = 0x1014 | ((class_code ? 0x8b : 0x102) << 16); /* a phb */
  158. else if (offset == PCI_REVISION_ID)
  159. *returnval = (class_code ? PCI_CLASS_BRIDGE_PCI : PCI_CLASS_BRIDGE_HOST) << 16; /* revs are zero */
  160. else if ((offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_5) || offset == PCI_ROM_ADDRESS)
  161. *returnval = 0;
  162. }
  163. /* printk("fake: %s nbytes=%d, offset=%lx ret=%lxn", class_code ? "EADS" : "PHB", nbytes, offset, *returnval); */
  164. return 0;
  165. }
  166. /******************************************************************
  167.  * pci_read_irq_line
  168.  *
  169.  * Reads the Interrupt Pin to determine if interrupt is use by card.
  170.  * If the interrupt is used, then gets the interrupt line from the 
  171.  * openfirmware and sets it in the pci_dev and pci_config line.
  172.  *
  173.  ******************************************************************/
  174. int 
  175. pci_read_irq_line(struct pci_dev *Pci_Dev)
  176. {
  177. u8 InterruptPin;
  178. struct device_node *Node;
  179.      pci_read_config_byte(Pci_Dev, PCI_INTERRUPT_PIN, &InterruptPin);
  180. if (InterruptPin == 0) {
  181. PPCDBG(PPCDBG_BUSWALK,"tDevice: %s No Interrupt used by device.n",Pci_Dev->slot_name);
  182. return 0;
  183. }
  184. Node = pci_device_to_OF_node(Pci_Dev);
  185. if ( Node == NULL) { 
  186. PPCDBG(PPCDBG_BUSWALK,"tDevice: %s Device Node not found.n",Pci_Dev->slot_name);
  187. return -1;
  188. }
  189. if (Node->n_intrs == 0)  {
  190. PPCDBG(PPCDBG_BUSWALK,"tDevice: %s No Device OF interrupts defined.n",Pci_Dev->slot_name);
  191. return -1;
  192. }
  193. Pci_Dev->irq = Node->intrs[0].line;
  194. if (s7a_workaround) {
  195. if (Pci_Dev->irq > 16)
  196. Pci_Dev->irq -= 3;
  197. }
  198. pci_write_config_byte(Pci_Dev, PCI_INTERRUPT_LINE, Pci_Dev->irq);
  199. PPCDBG(PPCDBG_BUSWALK,"tDevice: %s pci_dev->irq = 0x%02Xn",Pci_Dev->slot_name,Pci_Dev->irq);
  200. return 0;
  201. }
  202. /******************************************************************
  203.  * Find all PHBs in the system and initialize a set of data 
  204.  * structures to represent them.
  205.  ******************************************************************/
  206. unsigned long __init
  207. find_and_init_phbs(void)
  208. {
  209.         struct device_node *Pci_Node;
  210.         struct pci_controller *phb;
  211.         unsigned int root_addr_size_words = 0, this_addr_size_words = 0;
  212. unsigned int this_addr_count = 0, range_stride;
  213.         unsigned int *ui_ptr = NULL, *ranges;
  214.         char *model;
  215. struct pci_range64 range;
  216. struct resource *res;
  217. unsigned int memno, rlen, i, index;
  218. unsigned int *opprop;
  219. int has_isa = 0;
  220.         PPCDBG(PPCDBG_PHBINIT, "find_and_init_phbsn"); 
  221. read_pci_config = rtas_token("read-pci-config");
  222. write_pci_config = rtas_token("write-pci-config");
  223. ibm_read_pci_config = rtas_token("ibm,read-pci-config");
  224. ibm_write_pci_config = rtas_token("ibm,write-pci-config");
  225. eeh_init();
  226. if (naca->interrupt_controller == IC_OPEN_PIC) {
  227. opprop = (unsigned int *)get_property(find_path_device("/"),
  228. "platform-open-pic", NULL);
  229. }
  230. /* Get the root address word size. */
  231. ui_ptr = (unsigned int *) get_property(find_path_device("/"), 
  232.        "#size-cells", NULL);
  233. if (ui_ptr) {
  234. root_addr_size_words = *ui_ptr;
  235. } else {
  236. PPCDBG(PPCDBG_PHBINIT, "tget #size-cells failed.n"); 
  237. return(-1);
  238. }
  239. if (find_type_devices("isa")) {
  240. has_isa = 1;
  241. PPCDBG(PPCDBG_PHBINIT, "tFound an ISA bus.n"); 
  242. }
  243. index = 0;
  244. /******************************************************************
  245. * Find all PHB devices and create an object for them.
  246. ******************************************************************/
  247. for (Pci_Node = find_devices("pci"); Pci_Node != NULL; Pci_Node = Pci_Node->next) {
  248. model = (char *) get_property(Pci_Node, "model", NULL);
  249. if (model != NULL)  {
  250. phb = alloc_phb(Pci_Node, model, root_addr_size_words);
  251. if (phb == NULL) return(-1);
  252. }
  253. else {
  254.           continue;
  255. }
  256. /* Get this node's address word size. */
  257. ui_ptr = (unsigned int *) get_property(Pci_Node, "#size-cells", NULL);
  258. if (ui_ptr)
  259. this_addr_size_words = *ui_ptr;
  260. else
  261. this_addr_size_words = 1;
  262. /* Get this node's address word count. */
  263. ui_ptr = (unsigned int *) get_property(Pci_Node, "#address-cells", NULL);
  264. if (ui_ptr)
  265. this_addr_count = *ui_ptr;
  266. else
  267. this_addr_count = 3;
  268. range_stride = this_addr_count + root_addr_size_words + this_addr_size_words;
  269.       
  270. memno = 0;
  271. phb->io_base_phys = 0;
  272.          
  273. ranges = (unsigned int *) get_property(Pci_Node, "ranges", &rlen);
  274. PPCDBG(PPCDBG_PHBINIT, "trange_stride = 0x%lx, rlen = 0x%xn", range_stride, rlen);
  275.                 
  276. for (i = 0; i < (rlen/sizeof(*ranges)); i+=range_stride) {
  277.    /* Put the PCI addr part of the current element into a 
  278.  * '64' struct. 
  279.  */
  280.    range = *((struct pci_range64 *)(ranges + i));
  281. /* If this is a '32' element, map into a 64 struct. */
  282. if ((range_stride * sizeof(int)) == 
  283.    sizeof(struct pci_range32)) {
  284. range.parent_addr = 
  285. (unsigned long)(*(ranges + i + 3));
  286. range.size = 
  287. (((unsigned long)(*(ranges + i + 4)))<<32) | 
  288. (*(ranges + i + 5));
  289. } else {
  290. range.parent_addr = 
  291. (((unsigned long)(*(ranges + i + 3)))<<32) | 
  292. (*(ranges + i + 4));
  293. range.size = 
  294. (((unsigned long)(*(ranges + i + 5)))<<32) | 
  295. (*(ranges + i + 6));
  296. }
  297. PPCDBG(PPCDBG_PHBINIT, "trange.parent_addr    = 0x%lxn", 
  298.        range.parent_addr);
  299. PPCDBG(PPCDBG_PHBINIT, "trange.child_addr.hi  = 0x%lxn", 
  300.        range.child_addr.a_hi);
  301. PPCDBG(PPCDBG_PHBINIT, "trange.child_addr.mid = 0x%lxn", 
  302.        range.child_addr.a_mid);
  303. PPCDBG(PPCDBG_PHBINIT, "trange.child_addr.lo  = 0x%lxn", 
  304.        range.child_addr.a_lo);
  305. PPCDBG(PPCDBG_PHBINIT, "trange.size           = 0x%lxn", 
  306.        range.size);
  307. res = NULL;
  308.         switch ((range.child_addr.a_hi >> 24) & 0x3) {
  309. case 1: /* I/O space */
  310. PPCDBG(PPCDBG_PHBINIT, "tIO Spacen");
  311. phb->io_base_phys = range.parent_addr;
  312. res = &phb->io_resource;
  313. res->name = Pci_Node->full_name;
  314. res->flags = IORESOURCE_IO;
  315. if (is_eeh_implemented()) {
  316. if (!isa_io_base && has_isa) {
  317. /* map a page for ISA ports.  Not EEH protected. */
  318. isa_io_base = (unsigned long)__ioremap(phb->io_base_phys, PAGE_SIZE, _PAGE_NO_CACHE);
  319. }
  320. res->start = phb->io_base_virt = eeh_token(index, 0, 0, 0);
  321. res->end = eeh_token(index, 0xff, 0xff, 0xffffffff);
  322. } else {
  323. phb->io_base_virt = ioremap(phb->io_base_phys, range.size);
  324. if (!pci_io_base) {
  325. pci_io_base = (unsigned long)phb->io_base_virt;
  326. if (has_isa)
  327. isa_io_base = pci_io_base;
  328. }
  329. res->start = ((((unsigned long) range.child_addr.a_mid) << 32) | (range.child_addr.a_lo));
  330. res->start += (unsigned long)phb->io_base_virt;
  331. res->end =   res->start + range.size - 1;
  332. }
  333. res->parent = NULL;
  334. res->sibling = NULL;
  335. res->child = NULL;
  336. phb->pci_io_offset = range.parent_addr - 
  337. ((((unsigned long)
  338.    range.child_addr.a_mid) << 32) | 
  339.  (range.child_addr.a_lo));
  340. PPCDBG(PPCDBG_PHBINIT, "tpci_io_offset  = 0x%lxn", 
  341.        phb->pci_io_offset);
  342.    break;
  343. case 2: /* mem space */
  344. PPCDBG(PPCDBG_PHBINIT, "tMem Spacen");
  345. phb->pci_mem_offset = range.parent_addr - 
  346. ((((unsigned long)
  347.    range.child_addr.a_mid) << 32) | 
  348.  (range.child_addr.a_lo));
  349. PPCDBG(PPCDBG_PHBINIT, "tpci_mem_offset = 0x%lxn", 
  350.        phb->pci_mem_offset);
  351. if (memno < sizeof(phb->mem_resources)/sizeof(phb->mem_resources[0])) {
  352. res = &(phb->mem_resources[memno]);
  353. ++memno;
  354. res->name = Pci_Node->full_name;
  355. res->flags = IORESOURCE_MEM;
  356. if (is_eeh_implemented()) {
  357. res->start = eeh_token(index, 0, 0, 0);
  358. res->end =   eeh_token(index, 0xff, 0xff, 0xffffffff);
  359. } else {
  360. res->start = range.parent_addr;
  361. res->end =   range.parent_addr + range.size - 1;
  362. }
  363. res->parent = NULL;
  364. res->sibling = NULL;
  365. res->child = NULL;
  366. }
  367.    break;
  368. }
  369. }
  370. PPCDBG(PPCDBG_PHBINIT, "tphb->io_base_phys   = 0x%lxn", 
  371.        phb->io_base_phys); 
  372. PPCDBG(PPCDBG_PHBINIT, "tphb->pci_mem_offset = 0x%lxn", 
  373.        phb->pci_mem_offset); 
  374. if (naca->interrupt_controller == IC_OPEN_PIC) {
  375. int addr = root_addr_size_words * (index + 2) - 1;
  376. openpic_setup_ISU(index, opprop[addr]); 
  377. }
  378. index++;
  379. }
  380. pci_devs_phb_init();
  381. return 0;  /*Success */
  382. }
  383. /******************************************************************
  384.  *
  385.  * Allocate and partially initialize a structure to represent a PHB.
  386.  *
  387.  ******************************************************************/
  388. struct pci_controller *
  389. alloc_phb(struct device_node *dev, char *model, unsigned int addr_size_words)
  390. {
  391. struct pci_controller *phb;
  392. unsigned int *ui_ptr = NULL, len;
  393. struct reg_property64 reg_struct;
  394. int *bus_range;
  395. int *buid_vals;
  396. PPCDBG(PPCDBG_PHBINIT, "alloc_phb: %sn", dev->full_name); 
  397. PPCDBG(PPCDBG_PHBINIT, "tdev             = 0x%lxn", dev); 
  398. PPCDBG(PPCDBG_PHBINIT, "tmodel           = 0x%lxn", model); 
  399. PPCDBG(PPCDBG_PHBINIT, "taddr_size_words = 0x%lxn", addr_size_words); 
  400.   
  401. /* Found a PHB, now figure out where his registers are mapped. */
  402. ui_ptr = (unsigned int *) get_property(dev, "reg", &len);
  403. if (ui_ptr == NULL) {
  404. PPCDBG(PPCDBG_PHBINIT, "tget reg failed.n"); 
  405. return(NULL);
  406. }
  407. if (addr_size_words == 1) {
  408. reg_struct.address = ((struct reg_property32 *)ui_ptr)->address;
  409. reg_struct.size    = ((struct reg_property32 *)ui_ptr)->size;
  410. } else {
  411. reg_struct = *((struct reg_property64 *)ui_ptr);
  412. }
  413. PPCDBG(PPCDBG_PHBINIT, "treg_struct.address = 0x%lxn", reg_struct.address);
  414. PPCDBG(PPCDBG_PHBINIT, "treg_struct.size    = 0x%lxn", reg_struct.size); 
  415. /***************************************************************
  416. * Set chip specific data in the phb, including types & 
  417. * register pointers.
  418. ***************************************************************/
  419. /****************************************************************
  420. * Python
  421. ***************************************************************/
  422. if (strstr(model, "Python")) {
  423. PPCDBG(PPCDBG_PHBINIT, "tCreate pythonn");
  424.         phb = pci_alloc_pci_controller("PHB PY",phb_type_python);
  425. if (phb == NULL) return NULL;
  426.         phb->cfg_addr = (volatile unsigned long *) 
  427. ioremap(reg_struct.address + 0xf8000, PAGE_SIZE);
  428. PPCDBG(PPCDBG_PHBINIT, "tcfg_addr_r = 0x%lxn", 
  429.        reg_struct.address + 0xf8000);
  430. PPCDBG(PPCDBG_PHBINIT, "tcfg_addr_v = 0x%lxn", 
  431.        phb->cfg_addr);
  432. phb->cfg_data = (char*)(phb->cfg_addr + 0x02);
  433.         phb->phb_regs = (volatile unsigned long *) 
  434. ioremap(reg_struct.address + 0xf7000, PAGE_SIZE);
  435. /* Python's register file is 1 MB in size. */
  436. phb->chip_regs = ioremap(reg_struct.address & ~(0xfffffUL), 
  437.  0x100000); 
  438. /* 
  439.  * Firmware doesn't always clear this bit which is critical
  440.  * for good performance - Anton
  441.  */
  442. {
  443. volatile u32 *tmp, i;
  444. #define PRG_CL_RESET_VALID 0x00010000
  445. tmp = (u32 *)((unsigned long)phb->chip_regs + 0xf6030);
  446. if (*tmp & PRG_CL_RESET_VALID) {
  447. printk("Python workaround: ");
  448. *tmp &= ~PRG_CL_RESET_VALID;
  449. /*
  450.  * We must read it back for changes to
  451.  * take effect
  452.  */
  453. i = *tmp;
  454. printk("reg0: %xn", i);
  455. }
  456. }
  457. /***************************************************************
  458. * Speedwagon
  459. *   include Winnipeg as well for the time being.
  460. ***************************************************************/
  461. } else if ((strstr(model, "Speedwagon")) || 
  462.    (strstr(model, "Winnipeg"))) {
  463. PPCDBG(PPCDBG_PHBINIT, "tCreate speedwagonn");
  464.         phb = pci_alloc_pci_controller("PHB SW",phb_type_speedwagon);
  465. if (phb == NULL) return NULL;
  466. if (naca->platform == PLATFORM_PSERIES) {
  467. phb->cfg_addr = (volatile unsigned long *) 
  468.   ioremap(reg_struct.address + 0x140, PAGE_SIZE);
  469. phb->cfg_data = (char*)(phb->cfg_addr - 0x02); /* minus is correct */
  470. phb->phb_regs = (volatile unsigned long *) 
  471.   ioremap(reg_struct.address, PAGE_SIZE);
  472. /* Speedwagon's register file is 1 MB in size. */
  473. phb->chip_regs = ioremap(reg_struct.address & ~(0xfffffUL),
  474.  0x100000); 
  475. PPCDBG(PPCDBG_PHBINIT, "tmapping chip_regs from 0x%lx -> 0x%lxn", 
  476.        reg_struct.address & 0xfffff, phb->chip_regs);
  477. } else {
  478. phb->cfg_addr = NULL;
  479. phb->cfg_data = NULL; 
  480. phb->phb_regs = NULL;
  481. phb->chip_regs = NULL;
  482. }
  483. phb->local_number = ((reg_struct.address >> 12) & 0xf) - 0x8;
  484. /***************************************************************
  485. * Trying to build a known just gets the code in trouble.
  486. ***************************************************************/
  487. } else { 
  488. PPCDBG(PPCDBG_PHBINIT, "tUnknown PHB Type!n");
  489. printk("PCI: Unknown Phb Type!n");
  490. return NULL;
  491. }
  492. bus_range = (int *) get_property(dev, "bus-range", &len);
  493. if (bus_range == NULL || len < 2 * sizeof(int)) {
  494. PPCDBG(PPCDBG_PHBINIT, "Can't get bus-range for %sn", dev->full_name);
  495. kfree(phb);
  496. return(NULL);
  497. }
  498. /***************************************************************
  499. * Finished with the initialization
  500. ***************************************************************/
  501. phb->first_busno =  bus_range[0];
  502. phb->last_busno  =  bus_range[1];
  503. phb->arch_data   = dev;
  504. phb->ops = &rtas_pci_ops;
  505. buid_vals = (int *) get_property(dev, "ibm,fw-phb-id", &len);
  506.   if (buid_vals == NULL) {
  507. phb->buid = 0;
  508.   else {
  509. struct pci_bus check;
  510. if (sizeof(check.number) == 1 || sizeof(check.primary) == 1 ||
  511.     sizeof(check.secondary) == 1 || sizeof(check.subordinate) == 1) {
  512. udbg_printf("pSeries_pci:  this system has large bus numbers and the kernel was notn"
  513.       "built with the patch that fixes include/linux/pci.h struct pci_bus son"
  514.       "number, primary, secondary and subordinate are ints.n");
  515. panic("pSeries_pci:  this system has large bus numbers and the kernel was notn"
  516.       "built with the patch that fixes include/linux/pci.h struct pci_bus son"
  517.       "number, primary, secondary and subordinate are ints.n");
  518.     }
  519.     
  520.     if (len < 2 * sizeof(int))
  521.       phb->buid = (unsigned long)buid_vals[0];  // Support for new OF that only has 1 integer for buid.
  522.     else
  523.       phb->buid = (((unsigned long)buid_vals[0]) << 32UL) |
  524.                   (((unsigned long)buid_vals[1]) & 0xffffffff);
  525.   
  526. phb->first_busno += (phb->global_number << 8);
  527. phb->last_busno += (phb->global_number << 8);
  528. }
  529. /* Dump PHB information for Debug */
  530. PPCDBGCALL(PPCDBG_PHBINIT,dumpPci_Controller(phb) );
  531. return phb;
  532. }
  533. void 
  534. fixup_resources(struct pci_dev *dev)
  535. {
  536.   int i;
  537.   struct pci_controller *phb = PCI_GET_PHB_PTR(dev);
  538. struct device_node *dn;
  539. unsigned long eeh_disable_bit;
  540. /* Add IBM loc code (slot) as a prefix to the device names for service */
  541. dn = pci_device_to_OF_node(dev);
  542. if (dn) {
  543. char *loc_code = get_property(dn, "ibm,loc-code", 0);
  544. if (loc_code) {
  545. int loc_len = strlen(loc_code);
  546. if (loc_len < sizeof(dev->name)) {
  547. memmove(dev->name+loc_len+1, dev->name, sizeof(dev->name)-loc_len-1);
  548. memcpy(dev->name, loc_code, loc_len);
  549. dev->name[loc_len] = ' ';
  550. dev->name[sizeof(dev->name)-1] = '';
  551. }
  552. }
  553. }
  554. if (is_eeh_implemented()) {
  555. if (is_eeh_configured(dev)) {
  556. eeh_disable_bit = 0;
  557. if (eeh_set_option(dev, EEH_ENABLE) != 0) {
  558. printk("PCI: failed to enable EEH for %s %sn", dev->slot_name, dev->name);
  559. eeh_disable_bit = EEH_TOKEN_DISABLED;
  560. }
  561. } else {
  562. /* Assume device is by default EEH_DISABLE'd */
  563. printk("PCI: eeh NOT configured for %s %sn", dev->slot_name, dev->name);
  564. eeh_disable_bit = EEH_TOKEN_DISABLED;
  565. }
  566. }
  567. PPCDBG(PPCDBG_PHBINIT, "fixup_resources:n"); 
  568. PPCDBG(PPCDBG_PHBINIT, "tphb                 = 0x%016LXn", phb); 
  569. PPCDBG(PPCDBG_PHBINIT, "tphb->pci_io_offset  = 0x%016LXn", phb->pci_io_offset); 
  570. PPCDBG(PPCDBG_PHBINIT, "tphb->pci_mem_offset = 0x%016LXn", phb->pci_mem_offset); 
  571. PPCDBG(PPCDBG_PHBINIT, "tdev->name   = %sn", dev->name);
  572. PPCDBG(PPCDBG_PHBINIT, "tdev->vendor:device = 0x%04X : 0x%04Xn", dev->vendor, dev->device);
  573. if (phb == NULL)
  574. return;
  575.   for (i = 0; i <  DEVICE_COUNT_RESOURCE; ++i) {
  576. PPCDBG(PPCDBG_PHBINIT, "tdevice %x.%x[%d] (flags %x) [%lx..%lx]n",
  577.     dev->bus->number, dev->devfn, i,
  578.     dev->resource[i].flags,
  579.     dev->resource[i].start,
  580.     dev->resource[i].end);
  581. if ((dev->resource[i].start == 0) && (dev->resource[i].end == 0)) {
  582. continue;
  583. }
  584. if (dev->resource[i].start > dev->resource[i].end) {
  585. /* Bogus resource.  Just clear it out. */
  586. dev->resource[i].start = dev->resource[i].end = 0;
  587. continue;
  588. }
  589. if (dev->resource[i].flags & IORESOURCE_IO) {
  590. if (is_eeh_implemented()) {
  591. unsigned int busno = dev->bus ? dev->bus->number : 0;
  592. unsigned long size = dev->resource[i].end - dev->resource[i].start;
  593. unsigned long addr = (unsigned long)__ioremap(dev->resource[i].start + phb->io_base_phys, size, _PAGE_NO_CACHE);
  594. if (!addr)
  595. panic("fixup_resources: io ioremap failed!n");
  596. dev->resource[i].start = eeh_token(phb->global_number, busno, dev->devfn, addr) | eeh_disable_bit;
  597. dev->resource[i].end = dev->resource[i].start + size;
  598. } else {
  599. unsigned long offset = (unsigned long)phb->io_base_virt;
  600. dev->resource[i].start += offset;
  601. dev->resource[i].end += offset;
  602. }
  603. PPCDBG(PPCDBG_PHBINIT, "tt-> now [%lx .. %lx]n",
  604.        dev->resource[i].start, dev->resource[i].end);
  605. } else if (dev->resource[i].flags & IORESOURCE_MEM) {
  606. if (dev->resource[i].start == 0) {
  607. /* Bogus.  Probably an unused bridge. */
  608. dev->resource[i].end = 0;
  609. } else {
  610. if (is_eeh_implemented()) {
  611. unsigned int busno = dev->bus ? dev->bus->number : 0;
  612. unsigned long size = dev->resource[i].end - dev->resource[i].start;
  613. unsigned long addr = (unsigned long)__ioremap(dev->resource[i].start + phb->pci_mem_offset, size, _PAGE_NO_CACHE);
  614. if (!addr)
  615. panic("fixup_resources: mem ioremap failed!n");
  616. dev->resource[i].start = eeh_token(phb->global_number, busno, dev->devfn, addr) | eeh_disable_bit;
  617. dev->resource[i].end = dev->resource[i].start + size;
  618. } else {
  619. dev->resource[i].start += phb->pci_mem_offset;
  620. dev->resource[i].end += phb->pci_mem_offset;
  621. }
  622. }
  623. PPCDBG(PPCDBG_PHBINIT, "tt-> now [%lx..%lx]n",
  624.        dev->resource[i].start, dev->resource[i].end);
  625. } else {
  626. continue;
  627. }
  628.   /* zap the 2nd function of the winbond chip */
  629.   if (dev->resource[i].flags & IORESOURCE_IO
  630.       && dev->bus->number == 0 && dev->devfn == 0x81)
  631.   dev->resource[i].flags &= ~IORESOURCE_IO;
  632.   }
  633. }   
  634. static void check_s7a(void)
  635. {
  636. struct device_node *root;
  637. char *model;
  638. root = find_path_device("/");
  639. if (root) {
  640. model = get_property(root, "model", NULL);
  641. if (model && !strcmp(model, "IBM,7013-S7A"))
  642. s7a_workaround = 1;
  643. }
  644. }
  645. void __init
  646. pSeries_pcibios_fixup(void)
  647. {
  648. struct pci_dev *dev;
  649. PPCDBG(PPCDBG_PHBINIT, "pSeries_pcibios_fixup: startn");
  650. pci_assign_all_busses = 0;
  651. check_s7a();
  652. pci_for_each_dev(dev) {
  653. pci_read_irq_line(dev);
  654. PPCDBGCALL(PPCDBG_PHBINIT, dumpPci_Dev(dev) );
  655. }
  656. if (naca->interrupt_controller == IC_PPC_XIC) {
  657. xics_isa_init(); 
  658. }
  659. }
  660. /*********************************************************************** 
  661.  * pci_find_hose_for_OF_device
  662.  *
  663.  * This function finds the PHB that matching device_node in the 
  664.  * OpenFirmware by scanning all the pci_controllers.
  665.  * 
  666.  ***********************************************************************/
  667. struct pci_controller*
  668. pci_find_hose_for_OF_device(struct device_node *node)
  669. {
  670. while (node) {
  671. struct pci_controller *hose;
  672. for (hose=hose_head;hose;hose=hose->next)
  673. if (hose->arch_data == node)
  674. return hose;
  675. node=node->parent;
  676. }
  677. return NULL;
  678. }
  679. /*********************************************************************** 
  680.  * ppc64_pcibios_init
  681.  *  
  682.  * Chance to initialize and structures or variable before PCI Bus walk.
  683.  *  
  684.  ***********************************************************************/
  685. void 
  686. pSeries_pcibios_init(void)
  687. {
  688. PPCDBG(PPCDBG_PHBINIT, "tppc64_pcibios_init Entry.n"); 
  689. if (get_property(find_path_device("/rtas"),"ibm,fw-phb-id",NULL) != NULL) {
  690. PPCDBG(PPCDBG_PHBINIT, "tFound: ibm,fw-phb-idn"); 
  691. Pci_Large_Bus_System = 1;
  692. }
  693. }
  694. /*
  695.  * This is called very early before the page table is setup.
  696.  */
  697. void 
  698. pSeries_pcibios_init_early(void)
  699. {
  700. ppc_md.pcibios_read_config_byte = rtas_read_config_byte;
  701. ppc_md.pcibios_read_config_word = rtas_read_config_word;
  702. ppc_md.pcibios_read_config_dword = rtas_read_config_dword;
  703. ppc_md.pcibios_write_config_byte = rtas_write_config_byte;
  704. ppc_md.pcibios_write_config_word = rtas_write_config_word;
  705. ppc_md.pcibios_write_config_dword = rtas_write_config_dword;
  706. }
  707. /************************************************************************/
  708. /* Get a char* of the device physical location(U0.3-P1-I8)              */
  709. /* See the Product Topology in the RS/6000 Architecture.                */
  710. /************************************************************************/
  711. int device_Location(struct pci_dev *PciDev, char *BufPtr)
  712. {
  713. struct device_node *DevNode = (struct device_node *)PciDev->sysdata;
  714. return sprintf(BufPtr,"PCI: Bus%3d, Device%3d, Vendor %04X, Location %-12s",
  715.        PciDev->bus->number,
  716.        PCI_SLOT(PciDev->devfn),
  717.        PciDev->vendor,
  718.        (char*)get_property(DevNode,"ibm,loc-code",0));
  719. }
  720. /************************************************************************/
  721. /* Set the slot reset line to the state passed in.                      */
  722. /* This is the platform specific for code for the pci_reset_device      */
  723. /* function.                                                            */
  724. /************************************************************************/
  725. int pci_set_reset(struct pci_dev *PciDev, int state)
  726. {
  727. return -1;
  728. }