pci.c 18 KB

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