pci.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * Copyright (C) 2001 Allan Trautman, IBM Corporation
  3. *
  4. * iSeries specific routines for PCI.
  5. *
  6. * Based on code from pci.c and iSeries_pci.c 32bit
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/list.h>
  24. #include <linux/string.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/ide.h>
  28. #include <linux/pci.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/prom.h>
  32. #include <asm/machdep.h>
  33. #include <asm/pci-bridge.h>
  34. #include <asm/iommu.h>
  35. #include <asm/abs_addr.h>
  36. #include <asm/firmware.h>
  37. #include <asm/iseries/hv_call_xm.h>
  38. #include <asm/iseries/mf.h>
  39. #include <asm/iseries/iommu.h>
  40. #include <asm/ppc-pci.h>
  41. #include "irq.h"
  42. #include "pci.h"
  43. #include "call_pci.h"
  44. /*
  45. * Forward declares of prototypes.
  46. */
  47. static struct device_node *find_Device_Node(int bus, int devfn);
  48. static int Pci_Retry_Max = 3; /* Only retry 3 times */
  49. static int Pci_Error_Flag = 1; /* Set Retry Error on. */
  50. static struct pci_ops iSeries_pci_ops;
  51. /*
  52. * Table defines
  53. * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space.
  54. */
  55. #define IOMM_TABLE_MAX_ENTRIES 1024
  56. #define IOMM_TABLE_ENTRY_SIZE 0x0000000000400000UL
  57. #define BASE_IO_MEMORY 0xE000000000000000UL
  58. static unsigned long max_io_memory = BASE_IO_MEMORY;
  59. static long current_iomm_table_entry;
  60. /*
  61. * Lookup Tables.
  62. */
  63. static struct device_node *iomm_table[IOMM_TABLE_MAX_ENTRIES];
  64. static u8 iobar_table[IOMM_TABLE_MAX_ENTRIES];
  65. static const char pci_io_text[] = "iSeries PCI I/O";
  66. static DEFINE_SPINLOCK(iomm_table_lock);
  67. /*
  68. * iomm_table_allocate_entry
  69. *
  70. * Adds pci_dev entry in address translation table
  71. *
  72. * - Allocates the number of entries required in table base on BAR
  73. * size.
  74. * - Allocates starting at BASE_IO_MEMORY and increases.
  75. * - The size is round up to be a multiple of entry size.
  76. * - CurrentIndex is incremented to keep track of the last entry.
  77. * - Builds the resource entry for allocated BARs.
  78. */
  79. static void iomm_table_allocate_entry(struct pci_dev *dev, int bar_num)
  80. {
  81. struct resource *bar_res = &dev->resource[bar_num];
  82. long bar_size = pci_resource_len(dev, bar_num);
  83. /*
  84. * No space to allocate, quick exit, skip Allocation.
  85. */
  86. if (bar_size == 0)
  87. return;
  88. /*
  89. * Set Resource values.
  90. */
  91. spin_lock(&iomm_table_lock);
  92. bar_res->name = pci_io_text;
  93. bar_res->start = BASE_IO_MEMORY +
  94. IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
  95. bar_res->end = bar_res->start + bar_size - 1;
  96. /*
  97. * Allocate the number of table entries needed for BAR.
  98. */
  99. while (bar_size > 0 ) {
  100. iomm_table[current_iomm_table_entry] = dev->sysdata;
  101. iobar_table[current_iomm_table_entry] = bar_num;
  102. bar_size -= IOMM_TABLE_ENTRY_SIZE;
  103. ++current_iomm_table_entry;
  104. }
  105. max_io_memory = BASE_IO_MEMORY +
  106. IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
  107. spin_unlock(&iomm_table_lock);
  108. }
  109. /*
  110. * allocate_device_bars
  111. *
  112. * - Allocates ALL pci_dev BAR's and updates the resources with the
  113. * BAR value. BARS with zero length will have the resources
  114. * The HvCallPci_getBarParms is used to get the size of the BAR
  115. * space. It calls iomm_table_allocate_entry to allocate
  116. * each entry.
  117. * - Loops through The Bar resources(0 - 5) including the ROM
  118. * is resource(6).
  119. */
  120. static void allocate_device_bars(struct pci_dev *dev)
  121. {
  122. int bar_num;
  123. for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num)
  124. iomm_table_allocate_entry(dev, bar_num);
  125. }
  126. /*
  127. * Log error information to system console.
  128. * Filter out the device not there errors.
  129. * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx
  130. * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx
  131. * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx
  132. */
  133. static void pci_Log_Error(char *Error_Text, int Bus, int SubBus,
  134. int AgentId, int HvRc)
  135. {
  136. if (HvRc == 0x0302)
  137. return;
  138. printk(KERN_ERR "PCI: %s Failed: 0x%02X.%02X.%02X Rc: 0x%04X",
  139. Error_Text, Bus, SubBus, AgentId, HvRc);
  140. }
  141. /*
  142. * iSeries_pci_final_fixup(void)
  143. */
  144. void __init iSeries_pci_final_fixup(void)
  145. {
  146. struct pci_dev *pdev = NULL;
  147. struct device_node *node;
  148. int DeviceCount = 0;
  149. /* Fix up at the device node and pci_dev relationship */
  150. mf_display_src(0xC9000100);
  151. printk("pcibios_final_fixup\n");
  152. for_each_pci_dev(pdev) {
  153. node = find_Device_Node(pdev->bus->number, pdev->devfn);
  154. printk("pci dev %p (%x.%x), node %p\n", pdev,
  155. pdev->bus->number, pdev->devfn, node);
  156. if (node != NULL) {
  157. struct pci_dn *pdn = PCI_DN(node);
  158. const u32 *agent;
  159. agent = get_property(node, "linux,agent-id", NULL);
  160. if ((pdn != NULL) && (agent != NULL)) {
  161. u8 irq = iSeries_allocate_IRQ(pdn->busno, 0,
  162. pdn->bussubno);
  163. int err;
  164. err = HvCallXm_connectBusUnit(pdn->busno, pdn->bussubno,
  165. *agent, irq);
  166. if (err)
  167. pci_Log_Error("Connect Bus Unit",
  168. pdn->busno, pdn->bussubno, *agent, err);
  169. else {
  170. err = HvCallPci_configStore8(pdn->busno, pdn->bussubno,
  171. *agent,
  172. PCI_INTERRUPT_LINE,
  173. irq);
  174. if (err)
  175. pci_Log_Error("PciCfgStore Irq Failed!",
  176. pdn->busno, pdn->bussubno, *agent, err);
  177. }
  178. if (!err)
  179. pdev->irq = irq;
  180. }
  181. ++DeviceCount;
  182. pdev->sysdata = (void *)node;
  183. PCI_DN(node)->pcidev = pdev;
  184. allocate_device_bars(pdev);
  185. iSeries_Device_Information(pdev, DeviceCount);
  186. iommu_devnode_init_iSeries(pdev, node);
  187. } else
  188. printk("PCI: Device Tree not found for 0x%016lX\n",
  189. (unsigned long)pdev);
  190. }
  191. iSeries_activate_IRQs();
  192. mf_display_src(0xC9000200);
  193. }
  194. /*
  195. * Look down the chain to find the matching Device Device
  196. */
  197. static struct device_node *find_Device_Node(int bus, int devfn)
  198. {
  199. struct device_node *node;
  200. for (node = NULL; (node = of_find_all_nodes(node)); ) {
  201. struct pci_dn *pdn = PCI_DN(node);
  202. if (pdn && (bus == pdn->busno) && (devfn == pdn->devfn))
  203. return node;
  204. }
  205. return NULL;
  206. }
  207. #if 0
  208. /*
  209. * Returns the device node for the passed pci_dev
  210. * Sanity Check Node PciDev to passed pci_dev
  211. * If none is found, returns a NULL which the client must handle.
  212. */
  213. static struct device_node *get_Device_Node(struct pci_dev *pdev)
  214. {
  215. struct device_node *node;
  216. node = pdev->sysdata;
  217. if (node == NULL || PCI_DN(node)->pcidev != pdev)
  218. node = find_Device_Node(pdev->bus->number, pdev->devfn);
  219. return node;
  220. }
  221. #endif
  222. /*
  223. * Config space read and write functions.
  224. * For now at least, we look for the device node for the bus and devfn
  225. * that we are asked to access. It may be possible to translate the devfn
  226. * to a subbus and deviceid more directly.
  227. */
  228. static u64 hv_cfg_read_func[4] = {
  229. HvCallPciConfigLoad8, HvCallPciConfigLoad16,
  230. HvCallPciConfigLoad32, HvCallPciConfigLoad32
  231. };
  232. static u64 hv_cfg_write_func[4] = {
  233. HvCallPciConfigStore8, HvCallPciConfigStore16,
  234. HvCallPciConfigStore32, HvCallPciConfigStore32
  235. };
  236. /*
  237. * Read PCI config space
  238. */
  239. static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  240. int offset, int size, u32 *val)
  241. {
  242. struct device_node *node = find_Device_Node(bus->number, devfn);
  243. u64 fn;
  244. struct HvCallPci_LoadReturn ret;
  245. if (node == NULL)
  246. return PCIBIOS_DEVICE_NOT_FOUND;
  247. if (offset > 255) {
  248. *val = ~0;
  249. return PCIBIOS_BAD_REGISTER_NUMBER;
  250. }
  251. fn = hv_cfg_read_func[(size - 1) & 3];
  252. HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0);
  253. if (ret.rc != 0) {
  254. *val = ~0;
  255. return PCIBIOS_DEVICE_NOT_FOUND; /* or something */
  256. }
  257. *val = ret.value;
  258. return 0;
  259. }
  260. /*
  261. * Write PCI config space
  262. */
  263. static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  264. int offset, int size, u32 val)
  265. {
  266. struct device_node *node = find_Device_Node(bus->number, devfn);
  267. u64 fn;
  268. u64 ret;
  269. if (node == NULL)
  270. return PCIBIOS_DEVICE_NOT_FOUND;
  271. if (offset > 255)
  272. return PCIBIOS_BAD_REGISTER_NUMBER;
  273. fn = hv_cfg_write_func[(size - 1) & 3];
  274. ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0);
  275. if (ret != 0)
  276. return PCIBIOS_DEVICE_NOT_FOUND;
  277. return 0;
  278. }
  279. static struct pci_ops iSeries_pci_ops = {
  280. .read = iSeries_pci_read_config,
  281. .write = iSeries_pci_write_config
  282. };
  283. /*
  284. * Check Return Code
  285. * -> On Failure, print and log information.
  286. * Increment Retry Count, if exceeds max, panic partition.
  287. *
  288. * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234
  289. * PCI: Device 23.90 ReadL Retry( 1)
  290. * PCI: Device 23.90 ReadL Retry Successful(1)
  291. */
  292. static int CheckReturnCode(char *TextHdr, struct device_node *DevNode,
  293. int *retry, u64 ret)
  294. {
  295. if (ret != 0) {
  296. struct pci_dn *pdn = PCI_DN(DevNode);
  297. (*retry)++;
  298. printk("PCI: %s: Device 0x%04X:%02X I/O Error(%2d): 0x%04X\n",
  299. TextHdr, pdn->busno, pdn->devfn,
  300. *retry, (int)ret);
  301. /*
  302. * Bump the retry and check for retry count exceeded.
  303. * If, Exceeded, panic the system.
  304. */
  305. if (((*retry) > Pci_Retry_Max) &&
  306. (Pci_Error_Flag > 0)) {
  307. mf_display_src(0xB6000103);
  308. panic_timeout = 0;
  309. panic("PCI: Hardware I/O Error, SRC B6000103, "
  310. "Automatic Reboot Disabled.\n");
  311. }
  312. return -1; /* Retry Try */
  313. }
  314. return 0;
  315. }
  316. /*
  317. * Translate the I/O Address into a device node, bar, and bar offset.
  318. * Note: Make sure the passed variable end up on the stack to avoid
  319. * the exposure of being device global.
  320. */
  321. static inline struct device_node *xlate_iomm_address(
  322. const volatile void __iomem *IoAddress,
  323. u64 *dsaptr, u64 *BarOffsetPtr)
  324. {
  325. unsigned long OrigIoAddr;
  326. unsigned long BaseIoAddr;
  327. unsigned long TableIndex;
  328. struct device_node *DevNode;
  329. OrigIoAddr = (unsigned long __force)IoAddress;
  330. if ((OrigIoAddr < BASE_IO_MEMORY) || (OrigIoAddr >= max_io_memory))
  331. return NULL;
  332. BaseIoAddr = OrigIoAddr - BASE_IO_MEMORY;
  333. TableIndex = BaseIoAddr / IOMM_TABLE_ENTRY_SIZE;
  334. DevNode = iomm_table[TableIndex];
  335. if (DevNode != NULL) {
  336. int barnum = iobar_table[TableIndex];
  337. *dsaptr = iseries_ds_addr(DevNode) | (barnum << 24);
  338. *BarOffsetPtr = BaseIoAddr % IOMM_TABLE_ENTRY_SIZE;
  339. } else
  340. panic("PCI: Invalid PCI IoAddress detected!\n");
  341. return DevNode;
  342. }
  343. /*
  344. * Read MM I/O Instructions for the iSeries
  345. * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal
  346. * else, data is returned in Big Endian format.
  347. */
  348. static u8 iSeries_Read_Byte(const volatile void __iomem *IoAddress)
  349. {
  350. u64 BarOffset;
  351. u64 dsa;
  352. int retry = 0;
  353. struct HvCallPci_LoadReturn ret;
  354. struct device_node *DevNode =
  355. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  356. if (DevNode == NULL) {
  357. static unsigned long last_jiffies;
  358. static int num_printed;
  359. if ((jiffies - last_jiffies) > 60 * HZ) {
  360. last_jiffies = jiffies;
  361. num_printed = 0;
  362. }
  363. if (num_printed++ < 10)
  364. printk(KERN_ERR "iSeries_Read_Byte: invalid access at IO address %p\n",
  365. IoAddress);
  366. return 0xff;
  367. }
  368. do {
  369. HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, BarOffset, 0);
  370. } while (CheckReturnCode("RDB", DevNode, &retry, ret.rc) != 0);
  371. return ret.value;
  372. }
  373. static u16 iSeries_Read_Word(const volatile void __iomem *IoAddress)
  374. {
  375. u64 BarOffset;
  376. u64 dsa;
  377. int retry = 0;
  378. struct HvCallPci_LoadReturn ret;
  379. struct device_node *DevNode =
  380. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  381. if (DevNode == NULL) {
  382. static unsigned long last_jiffies;
  383. static int num_printed;
  384. if ((jiffies - last_jiffies) > 60 * HZ) {
  385. last_jiffies = jiffies;
  386. num_printed = 0;
  387. }
  388. if (num_printed++ < 10)
  389. printk(KERN_ERR "iSeries_Read_Word: invalid access at IO address %p\n",
  390. IoAddress);
  391. return 0xffff;
  392. }
  393. do {
  394. HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa,
  395. BarOffset, 0);
  396. } while (CheckReturnCode("RDW", DevNode, &retry, ret.rc) != 0);
  397. return ret.value;
  398. }
  399. static u32 iSeries_Read_Long(const volatile void __iomem *IoAddress)
  400. {
  401. u64 BarOffset;
  402. u64 dsa;
  403. int retry = 0;
  404. struct HvCallPci_LoadReturn ret;
  405. struct device_node *DevNode =
  406. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  407. if (DevNode == NULL) {
  408. static unsigned long last_jiffies;
  409. static int num_printed;
  410. if ((jiffies - last_jiffies) > 60 * HZ) {
  411. last_jiffies = jiffies;
  412. num_printed = 0;
  413. }
  414. if (num_printed++ < 10)
  415. printk(KERN_ERR "iSeries_Read_Long: invalid access at IO address %p\n",
  416. IoAddress);
  417. return 0xffffffff;
  418. }
  419. do {
  420. HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa,
  421. BarOffset, 0);
  422. } while (CheckReturnCode("RDL", DevNode, &retry, ret.rc) != 0);
  423. return ret.value;
  424. }
  425. /*
  426. * Write MM I/O Instructions for the iSeries
  427. *
  428. */
  429. static void iSeries_Write_Byte(u8 data, volatile void __iomem *IoAddress)
  430. {
  431. u64 BarOffset;
  432. u64 dsa;
  433. int retry = 0;
  434. u64 rc;
  435. struct device_node *DevNode =
  436. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  437. if (DevNode == NULL) {
  438. static unsigned long last_jiffies;
  439. static int num_printed;
  440. if ((jiffies - last_jiffies) > 60 * HZ) {
  441. last_jiffies = jiffies;
  442. num_printed = 0;
  443. }
  444. if (num_printed++ < 10)
  445. printk(KERN_ERR "iSeries_Write_Byte: invalid access at IO address %p\n", IoAddress);
  446. return;
  447. }
  448. do {
  449. rc = HvCall4(HvCallPciBarStore8, dsa, BarOffset, data, 0);
  450. } while (CheckReturnCode("WWB", DevNode, &retry, rc) != 0);
  451. }
  452. static void iSeries_Write_Word(u16 data, volatile void __iomem *IoAddress)
  453. {
  454. u64 BarOffset;
  455. u64 dsa;
  456. int retry = 0;
  457. u64 rc;
  458. struct device_node *DevNode =
  459. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  460. if (DevNode == NULL) {
  461. static unsigned long last_jiffies;
  462. static int num_printed;
  463. if ((jiffies - last_jiffies) > 60 * HZ) {
  464. last_jiffies = jiffies;
  465. num_printed = 0;
  466. }
  467. if (num_printed++ < 10)
  468. printk(KERN_ERR "iSeries_Write_Word: invalid access at IO address %p\n",
  469. IoAddress);
  470. return;
  471. }
  472. do {
  473. rc = HvCall4(HvCallPciBarStore16, dsa, BarOffset, data, 0);
  474. } while (CheckReturnCode("WWW", DevNode, &retry, rc) != 0);
  475. }
  476. static void iSeries_Write_Long(u32 data, volatile void __iomem *IoAddress)
  477. {
  478. u64 BarOffset;
  479. u64 dsa;
  480. int retry = 0;
  481. u64 rc;
  482. struct device_node *DevNode =
  483. xlate_iomm_address(IoAddress, &dsa, &BarOffset);
  484. if (DevNode == NULL) {
  485. static unsigned long last_jiffies;
  486. static int num_printed;
  487. if ((jiffies - last_jiffies) > 60 * HZ) {
  488. last_jiffies = jiffies;
  489. num_printed = 0;
  490. }
  491. if (num_printed++ < 10)
  492. printk(KERN_ERR "iSeries_Write_Long: invalid access at IO address %p\n",
  493. IoAddress);
  494. return;
  495. }
  496. do {
  497. rc = HvCall4(HvCallPciBarStore32, dsa, BarOffset, data, 0);
  498. } while (CheckReturnCode("WWL", DevNode, &retry, rc) != 0);
  499. }
  500. static u8 iseries_readb(const volatile void __iomem *addr)
  501. {
  502. return iSeries_Read_Byte(addr);
  503. }
  504. static u16 iseries_readw(const volatile void __iomem *addr)
  505. {
  506. return le16_to_cpu(iSeries_Read_Word(addr));
  507. }
  508. static u32 iseries_readl(const volatile void __iomem *addr)
  509. {
  510. return le32_to_cpu(iSeries_Read_Long(addr));
  511. }
  512. static u16 iseries_readw_be(const volatile void __iomem *addr)
  513. {
  514. return iSeries_Read_Word(addr);
  515. }
  516. static u32 iseries_readl_be(const volatile void __iomem *addr)
  517. {
  518. return iSeries_Read_Long(addr);
  519. }
  520. static void iseries_writeb(u8 data, volatile void __iomem *addr)
  521. {
  522. iSeries_Write_Byte(data, addr);
  523. }
  524. static void iseries_writew(u16 data, volatile void __iomem *addr)
  525. {
  526. iSeries_Write_Word(cpu_to_le16(data), addr);
  527. }
  528. static void iseries_writel(u32 data, volatile void __iomem *addr)
  529. {
  530. iSeries_Write_Long(cpu_to_le32(data), addr);
  531. }
  532. static void iseries_writew_be(u16 data, volatile void __iomem *addr)
  533. {
  534. iSeries_Write_Word(data, addr);
  535. }
  536. static void iseries_writel_be(u32 data, volatile void __iomem *addr)
  537. {
  538. iSeries_Write_Long(data, addr);
  539. }
  540. static void iseries_readsb(const volatile void __iomem *addr, void *buf,
  541. unsigned long count)
  542. {
  543. u8 *dst = buf;
  544. while(count-- > 0)
  545. *(dst++) = iSeries_Read_Byte(addr);
  546. }
  547. static void iseries_readsw(const volatile void __iomem *addr, void *buf,
  548. unsigned long count)
  549. {
  550. u16 *dst = buf;
  551. while(count-- > 0)
  552. *(dst++) = iSeries_Read_Word(addr);
  553. }
  554. static void iseries_readsl(const volatile void __iomem *addr, void *buf,
  555. unsigned long count)
  556. {
  557. u32 *dst = buf;
  558. while(count-- > 0)
  559. *(dst++) = iSeries_Read_Long(addr);
  560. }
  561. static void iseries_writesb(volatile void __iomem *addr, const void *buf,
  562. unsigned long count)
  563. {
  564. const u8 *src = buf;
  565. while(count-- > 0)
  566. iSeries_Write_Byte(*(src++), addr);
  567. }
  568. static void iseries_writesw(volatile void __iomem *addr, const void *buf,
  569. unsigned long count)
  570. {
  571. const u16 *src = buf;
  572. while(count-- > 0)
  573. iSeries_Write_Word(*(src++), addr);
  574. }
  575. static void iseries_writesl(volatile void __iomem *addr, const void *buf,
  576. unsigned long count)
  577. {
  578. const u32 *src = buf;
  579. while(count-- > 0)
  580. iSeries_Write_Long(*(src++), addr);
  581. }
  582. static void iseries_memset_io(volatile void __iomem *addr, int c,
  583. unsigned long n)
  584. {
  585. volatile char __iomem *d = addr;
  586. while (n-- > 0)
  587. iSeries_Write_Byte(c, d++);
  588. }
  589. static void iseries_memcpy_fromio(void *dest, const volatile void __iomem *src,
  590. unsigned long n)
  591. {
  592. char *d = dest;
  593. const volatile char __iomem *s = src;
  594. while (n-- > 0)
  595. *d++ = iSeries_Read_Byte(s++);
  596. }
  597. static void iseries_memcpy_toio(volatile void __iomem *dest, const void *src,
  598. unsigned long n)
  599. {
  600. const char *s = src;
  601. volatile char __iomem *d = dest;
  602. while (n-- > 0)
  603. iSeries_Write_Byte(*s++, d++);
  604. }
  605. /* We only set MMIO ops. The default PIO ops will be default
  606. * to the MMIO ops + pci_io_base which is 0 on iSeries as
  607. * expected so both should work.
  608. *
  609. * Note that we don't implement the readq/writeq versions as
  610. * I don't know of an HV call for doing so. Thus, the default
  611. * operation will be used instead, which will fault a the value
  612. * return by iSeries for MMIO addresses always hits a non mapped
  613. * area. This is as good as the BUG() we used to have there.
  614. */
  615. static struct ppc_pci_io __initdata iseries_pci_io = {
  616. .readb = iseries_readb,
  617. .readw = iseries_readw,
  618. .readl = iseries_readl,
  619. .readw_be = iseries_readw_be,
  620. .readl_be = iseries_readl_be,
  621. .writeb = iseries_writeb,
  622. .writew = iseries_writew,
  623. .writel = iseries_writel,
  624. .writew_be = iseries_writew_be,
  625. .writel_be = iseries_writel_be,
  626. .readsb = iseries_readsb,
  627. .readsw = iseries_readsw,
  628. .readsl = iseries_readsl,
  629. .writesb = iseries_writesb,
  630. .writesw = iseries_writesw,
  631. .writesl = iseries_writesl,
  632. .memset_io = iseries_memset_io,
  633. .memcpy_fromio = iseries_memcpy_fromio,
  634. .memcpy_toio = iseries_memcpy_toio,
  635. };
  636. /*
  637. * iSeries_pcibios_init
  638. *
  639. * Description:
  640. * This function checks for all possible system PCI host bridges that connect
  641. * PCI buses. The system hypervisor is queried as to the guest partition
  642. * ownership status. A pci_controller is built for any bus which is partially
  643. * owned or fully owned by this guest partition.
  644. */
  645. void __init iSeries_pcibios_init(void)
  646. {
  647. struct pci_controller *phb;
  648. struct device_node *root = of_find_node_by_path("/");
  649. struct device_node *node = NULL;
  650. /* Install IO hooks */
  651. ppc_pci_io = iseries_pci_io;
  652. if (root == NULL) {
  653. printk(KERN_CRIT "iSeries_pcibios_init: can't find root "
  654. "of device tree\n");
  655. return;
  656. }
  657. while ((node = of_get_next_child(root, node)) != NULL) {
  658. HvBusNumber bus;
  659. const u32 *busp;
  660. if ((node->type == NULL) || (strcmp(node->type, "pci") != 0))
  661. continue;
  662. busp = get_property(node, "bus-range", NULL);
  663. if (busp == NULL)
  664. continue;
  665. bus = *busp;
  666. printk("bus %d appears to exist\n", bus);
  667. phb = pcibios_alloc_controller(node);
  668. if (phb == NULL)
  669. continue;
  670. phb->pci_mem_offset = phb->local_number = bus;
  671. phb->first_busno = bus;
  672. phb->last_busno = bus;
  673. phb->ops = &iSeries_pci_ops;
  674. }
  675. of_node_put(root);
  676. pci_devs_phb_init();
  677. }