pci.c 19 KB

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