pci.c 17.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
/*
 * Copyright (C) 2001 Allan Trautman, IBM Corporation
 *
 * iSeries specific routines for PCI.
5
 *
L
Linus Torvalds 已提交
6 7 8 9 10 11
 * Based on code from pci.c and iSeries_pci.c 32bit
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
12
 *
L
Linus Torvalds 已提交
13 14 15 16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
17
 *
L
Linus Torvalds 已提交
18 19 20 21 22
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */
#include <linux/kernel.h>
23
#include <linux/list.h>
L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31 32 33 34 35
#include <linux/string.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/ide.h>
#include <linux/pci.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/prom.h>
#include <asm/machdep.h>
#include <asm/pci-bridge.h>
#include <asm/iommu.h>
36
#include <asm/abs_addr.h>
L
Linus Torvalds 已提交
37

38
#include <asm/iseries/hv_call_xm.h>
39
#include <asm/iseries/mf.h>
40
#include <asm/iseries/iommu.h>
L
Linus Torvalds 已提交
41

42
#include <asm/ppc-pci.h>
L
Linus Torvalds 已提交
43

44
#include "irq.h"
45
#include "pci.h"
46
#include "call_pci.h"
47

L
Linus Torvalds 已提交
48
/*
49
 * Forward declares of prototypes.
L
Linus Torvalds 已提交
50
 */
51
static struct device_node *find_Device_Node(int bus, int devfn);
L
Linus Torvalds 已提交
52

53
static int Pci_Retry_Max = 3;	/* Only retry 3 times  */
L
Linus Torvalds 已提交
54 55 56 57 58 59 60 61 62 63 64 65
static int Pci_Error_Flag = 1;	/* Set Retry Error on. */

static struct pci_ops iSeries_pci_ops;

/*
 * Table defines
 * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space.
 */
#define IOMM_TABLE_MAX_ENTRIES	1024
#define IOMM_TABLE_ENTRY_SIZE	0x0000000000400000UL
#define BASE_IO_MEMORY		0xE000000000000000UL

66
static unsigned long max_io_memory = BASE_IO_MEMORY;
L
Linus Torvalds 已提交
67 68 69 70 71
static long current_iomm_table_entry;

/*
 * Lookup Tables.
 */
72 73
static struct device_node *iomm_table[IOMM_TABLE_MAX_ENTRIES];
static u8 iobar_table[IOMM_TABLE_MAX_ENTRIES];
L
Linus Torvalds 已提交
74

75
static const char pci_io_text[] = "iSeries PCI I/O";
L
Linus Torvalds 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
static DEFINE_SPINLOCK(iomm_table_lock);

/*
 * iomm_table_allocate_entry
 *
 * Adds pci_dev entry in address translation table
 *
 * - Allocates the number of entries required in table base on BAR
 *   size.
 * - Allocates starting at BASE_IO_MEMORY and increases.
 * - The size is round up to be a multiple of entry size.
 * - CurrentIndex is incremented to keep track of the last entry.
 * - Builds the resource entry for allocated BARs.
 */
static void iomm_table_allocate_entry(struct pci_dev *dev, int bar_num)
{
	struct resource *bar_res = &dev->resource[bar_num];
	long bar_size = pci_resource_len(dev, bar_num);

	/*
	 * No space to allocate, quick exit, skip Allocation.
	 */
	if (bar_size == 0)
		return;
	/*
	 * Set Resource values.
	 */
	spin_lock(&iomm_table_lock);
	bar_res->name = pci_io_text;
105
	bar_res->start = BASE_IO_MEMORY +
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113 114 115 116 117
		IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
	bar_res->end = bar_res->start + bar_size - 1;
	/*
	 * Allocate the number of table entries needed for BAR.
	 */
	while (bar_size > 0 ) {
		iomm_table[current_iomm_table_entry] = dev->sysdata;
		iobar_table[current_iomm_table_entry] = bar_num;
		bar_size -= IOMM_TABLE_ENTRY_SIZE;
		++current_iomm_table_entry;
	}
	max_io_memory = BASE_IO_MEMORY +
118
		IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
L
Linus Torvalds 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
	spin_unlock(&iomm_table_lock);
}

/*
 * allocate_device_bars
 *
 * - Allocates ALL pci_dev BAR's and updates the resources with the
 *   BAR value.  BARS with zero length will have the resources
 *   The HvCallPci_getBarParms is used to get the size of the BAR
 *   space.  It calls iomm_table_allocate_entry to allocate
 *   each entry.
 * - Loops through The Bar resources(0 - 5) including the ROM
 *   is resource(6).
 */
static void allocate_device_bars(struct pci_dev *dev)
{
	int bar_num;

137
	for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num)
L
Linus Torvalds 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
		iomm_table_allocate_entry(dev, bar_num);
}

/*
 * Log error information to system console.
 * Filter out the device not there errors.
 * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx
 * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx
 * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx
 */
static void pci_Log_Error(char *Error_Text, int Bus, int SubBus,
		int AgentId, int HvRc)
{
	if (HvRc == 0x0302)
		return;
	printk(KERN_ERR "PCI: %s Failed: 0x%02X.%02X.%02X Rc: 0x%04X",
	       Error_Text, Bus, SubBus, AgentId, HvRc);
}

/*
158
 * iSeries_pcibios_init
L
Linus Torvalds 已提交
159 160 161 162 163 164 165
 *
 * Description:
 *   This function checks for all possible system PCI host bridges that connect
 *   PCI buses.  The system hypervisor is queried as to the guest partition
 *   ownership status.  A pci_controller is built for any bus which is partially
 *   owned or fully owned by this guest partition.
 */
166
void iSeries_pcibios_init(void)
L
Linus Torvalds 已提交
167 168
{
	struct pci_controller *phb;
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	struct device_node *node;
	struct device_node *dn;

	for_each_node_by_type(node, "pci") {
		HvBusNumber bus;
		u32 *busp;

		busp = (u32 *)get_property(node, "bus-range", NULL);
		if (busp == NULL)
			continue;
		bus = *busp;
		printk("bus %d appears to exist\n", bus);
		phb = pcibios_alloc_controller(node);
		if (phb == NULL)
			continue;

		phb->pci_mem_offset = phb->local_number = bus;
		phb->first_busno = bus;
		phb->last_busno = bus;
		phb->ops = &iSeries_pci_ops;

		/* Find and connect the devices. */
		for (dn = NULL; (dn = of_get_next_child(node, dn)) != NULL;) {
			struct pci_dn *pdn;
			u32 *reg;
			u32 *lsn;

			reg = (u32 *)get_property(dn, "reg", NULL);
			if (reg == NULL) {
				printk(KERN_DEBUG "no reg property!\n");
				continue;
			}
			busp = (u32 *)get_property(dn, "linux,subbus", NULL);
			if (busp == NULL) {
				printk(KERN_DEBUG "no subbus property!\n");
				continue;
			}
			lsn = (u32 *)get_property(dn,
					"linux,logical-slot-number", NULL);
			if (lsn == NULL) {
				printk(KERN_DEBUG "no logical-slot-number\n");
				continue;
			}
L
Linus Torvalds 已提交
212

213 214 215 216 217 218 219 220 221
			pdn = kzalloc(sizeof(*pdn), GFP_KERNEL);
			if (pdn == NULL)
				return;
			dn->data = pdn;
			pdn->node = dn;
			pdn->busno = bus;
			pdn->devfn = (reg[0] >> 8) & 0xff;
			pdn->bussubno = *busp;
			pdn->LogicalSlot = *lsn;
L
Linus Torvalds 已提交
222 223 224 225 226
		}
	}
}

/*
227
 * iSeries_pci_final_fixup(void)
L
Linus Torvalds 已提交
228 229 230 231
 */
void __init iSeries_pci_final_fixup(void)
{
	struct pci_dev *pdev = NULL;
232
	struct device_node *node;
233
	int DeviceCount = 0;
L
Linus Torvalds 已提交
234 235 236 237 238 239 240 241 242 243 244

	/* Fix up at the device node and pci_dev relationship */
	mf_display_src(0xC9000100);

	printk("pcibios_final_fixup\n");
	for_each_pci_dev(pdev) {
		node = find_Device_Node(pdev->bus->number, pdev->devfn);
		printk("pci dev %p (%x.%x), node %p\n", pdev,
		       pdev->bus->number, pdev->devfn, node);

		if (node != NULL) {
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
			struct pci_dn *pdn = PCI_DN(node);
			u32 *agent;

			agent = (u32 *)get_property(node, "linux,agent-id",
					NULL);
			if ((pdn != NULL) && (agent != NULL)) {
				u8 irq = iSeries_allocate_IRQ(pdn->busno, 0,
						pdn->bussubno);
				int err;

				err = HvCallXm_connectBusUnit(pdn->busno, pdn->bussubno,
						*agent, irq);
				if (err)
					pci_Log_Error("Connect Bus Unit",
						pdn->busno, pdn->bussubno, *agent, err);
				else {
					err = HvCallPci_configStore8(pdn->busno, pdn->bussubno,
							*agent,
							PCI_INTERRUPT_LINE,
							irq);
					if (err)
						pci_Log_Error("PciCfgStore Irq Failed!",
							pdn->busno, pdn->bussubno, *agent, err);
				}
				if (!err)
					pdev->irq = irq;
			}

L
Linus Torvalds 已提交
273 274
			++DeviceCount;
			pdev->sysdata = (void *)node;
275
			PCI_DN(node)->pcidev = pdev;
L
Linus Torvalds 已提交
276
			allocate_device_bars(pdev);
277
			iSeries_Device_Information(pdev, DeviceCount);
L
Linus Torvalds 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
			iommu_devnode_init_iSeries(node);
		} else
			printk("PCI: Device Tree not found for 0x%016lX\n",
					(unsigned long)pdev);
	}
	iSeries_activate_IRQs();
	mf_display_src(0xC9000200);
}

void pcibios_fixup_bus(struct pci_bus *PciBus)
{
}

void pcibios_fixup_resources(struct pci_dev *pdev)
{
293
}
L
Linus Torvalds 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

/*
 * I/0 Memory copy MUST use mmio commands on iSeries
 * To do; For performance, include the hv call directly
 */
void iSeries_memset_io(volatile void __iomem *dest, char c, size_t Count)
{
	u8 ByteValue = c;
	long NumberOfBytes = Count;

	while (NumberOfBytes > 0) {
		iSeries_Write_Byte(ByteValue, dest++);
		-- NumberOfBytes;
	}
}
EXPORT_SYMBOL(iSeries_memset_io);

void iSeries_memcpy_toio(volatile void __iomem *dest, void *source, size_t count)
{
	char *src = source;
	long NumberOfBytes = count;

	while (NumberOfBytes > 0) {
		iSeries_Write_Byte(*src++, dest++);
		-- NumberOfBytes;
	}
}
EXPORT_SYMBOL(iSeries_memcpy_toio);

void iSeries_memcpy_fromio(void *dest, const volatile void __iomem *src, size_t count)
{
	char *dst = dest;
	long NumberOfBytes = count;

	while (NumberOfBytes > 0) {
		*dst++ = iSeries_Read_Byte(src++);
		-- NumberOfBytes;
	}
}
EXPORT_SYMBOL(iSeries_memcpy_fromio);

/*
 * Look down the chain to find the matching Device Device
 */
338
static struct device_node *find_Device_Node(int bus, int devfn)
L
Linus Torvalds 已提交
339
{
340 341 342 343
	struct device_node *node;

	for (node = NULL; (node = of_find_all_nodes(node)); ) {
		struct pci_dn *pdn = PCI_DN(node);
L
Linus Torvalds 已提交
344

345 346
		if (pdn && (bus == pdn->busno) && (devfn == pdn->devfn))
			return node;
L
Linus Torvalds 已提交
347 348 349 350 351 352 353 354 355 356
	}
	return NULL;
}

#if 0
/*
 * Returns the device node for the passed pci_dev
 * Sanity Check Node PciDev to passed pci_dev
 * If none is found, returns a NULL which the client must handle.
 */
357
static struct device_node *get_Device_Node(struct pci_dev *pdev)
L
Linus Torvalds 已提交
358
{
359
	struct device_node *node;
L
Linus Torvalds 已提交
360 361

	node = pdev->sysdata;
362
	if (node == NULL || PCI_DN(node)->pcidev != pdev)
L
Linus Torvalds 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
		node = find_Device_Node(pdev->bus->number, pdev->devfn);
	return node;
}
#endif

/*
 * Config space read and write functions.
 * For now at least, we look for the device node for the bus and devfn
 * that we are asked to access.  It may be possible to translate the devfn
 * to a subbus and deviceid more directly.
 */
static u64 hv_cfg_read_func[4]  = {
	HvCallPciConfigLoad8, HvCallPciConfigLoad16,
	HvCallPciConfigLoad32, HvCallPciConfigLoad32
};

static u64 hv_cfg_write_func[4] = {
	HvCallPciConfigStore8, HvCallPciConfigStore16,
	HvCallPciConfigStore32, HvCallPciConfigStore32
};

/*
 * Read PCI config space
 */
static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn,
		int offset, int size, u32 *val)
{
390
	struct device_node *node = find_Device_Node(bus->number, devfn);
L
Linus Torvalds 已提交
391 392 393 394 395 396 397 398 399 400 401
	u64 fn;
	struct HvCallPci_LoadReturn ret;

	if (node == NULL)
		return PCIBIOS_DEVICE_NOT_FOUND;
	if (offset > 255) {
		*val = ~0;
		return PCIBIOS_BAD_REGISTER_NUMBER;
	}

	fn = hv_cfg_read_func[(size - 1) & 3];
402
	HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0);
L
Linus Torvalds 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419

	if (ret.rc != 0) {
		*val = ~0;
		return PCIBIOS_DEVICE_NOT_FOUND;	/* or something */
	}

	*val = ret.value;
	return 0;
}

/*
 * Write PCI config space
 */

static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn,
		int offset, int size, u32 val)
{
420
	struct device_node *node = find_Device_Node(bus->number, devfn);
L
Linus Torvalds 已提交
421 422 423 424 425 426 427 428 429
	u64 fn;
	u64 ret;

	if (node == NULL)
		return PCIBIOS_DEVICE_NOT_FOUND;
	if (offset > 255)
		return PCIBIOS_BAD_REGISTER_NUMBER;

	fn = hv_cfg_write_func[(size - 1) & 3];
430
	ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0);
L
Linus Torvalds 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451

	if (ret != 0)
		return PCIBIOS_DEVICE_NOT_FOUND;

	return 0;
}

static struct pci_ops iSeries_pci_ops = {
	.read = iSeries_pci_read_config,
	.write = iSeries_pci_write_config
};

/*
 * Check Return Code
 * -> On Failure, print and log information.
 *    Increment Retry Count, if exceeds max, panic partition.
 *
 * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234
 * PCI: Device 23.90 ReadL Retry( 1)
 * PCI: Device 23.90 ReadL Retry Successful(1)
 */
452
static int CheckReturnCode(char *TextHdr, struct device_node *DevNode,
453
		int *retry, u64 ret)
L
Linus Torvalds 已提交
454 455
{
	if (ret != 0)  {
456 457
		struct pci_dn *pdn = PCI_DN(DevNode);

458
		(*retry)++;
L
Linus Torvalds 已提交
459
		printk("PCI: %s: Device 0x%04X:%02X  I/O Error(%2d): 0x%04X\n",
460
				TextHdr, pdn->busno, pdn->devfn,
461
				*retry, (int)ret);
L
Linus Torvalds 已提交
462 463 464 465
		/*
		 * Bump the retry and check for retry count exceeded.
		 * If, Exceeded, panic the system.
		 */
466
		if (((*retry) > Pci_Retry_Max) &&
L
Linus Torvalds 已提交
467 468
				(Pci_Error_Flag > 0)) {
			mf_display_src(0xB6000103);
469
			panic_timeout = 0;
L
Linus Torvalds 已提交
470 471 472 473 474
			panic("PCI: Hardware I/O Error, SRC B6000103, "
					"Automatic Reboot Disabled.\n");
		}
		return -1;	/* Retry Try */
	}
475
	return 0;
L
Linus Torvalds 已提交
476 477 478 479 480 481 482
}

/*
 * Translate the I/O Address into a device node, bar, and bar offset.
 * Note: Make sure the passed variable end up on the stack to avoid
 * the exposure of being device global.
 */
483
static inline struct device_node *xlate_iomm_address(
L
Linus Torvalds 已提交
484 485 486 487 488 489
		const volatile void __iomem *IoAddress,
		u64 *dsaptr, u64 *BarOffsetPtr)
{
	unsigned long OrigIoAddr;
	unsigned long BaseIoAddr;
	unsigned long TableIndex;
490
	struct device_node *DevNode;
L
Linus Torvalds 已提交
491 492 493 494 495 496 497 498 499 500

	OrigIoAddr = (unsigned long __force)IoAddress;
	if ((OrigIoAddr < BASE_IO_MEMORY) || (OrigIoAddr >= max_io_memory))
		return NULL;
	BaseIoAddr = OrigIoAddr - BASE_IO_MEMORY;
	TableIndex = BaseIoAddr / IOMM_TABLE_ENTRY_SIZE;
	DevNode = iomm_table[TableIndex];

	if (DevNode != NULL) {
		int barnum = iobar_table[TableIndex];
501
		*dsaptr = iseries_ds_addr(DevNode) | (barnum << 24);
L
Linus Torvalds 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
		*BarOffsetPtr = BaseIoAddr % IOMM_TABLE_ENTRY_SIZE;
	} else
		panic("PCI: Invalid PCI IoAddress detected!\n");
	return DevNode;
}

/*
 * Read MM I/O Instructions for the iSeries
 * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal
 * else, data is returned in big Endian format.
 *
 * iSeries_Read_Byte = Read Byte  ( 8 bit)
 * iSeries_Read_Word = Read Word  (16 bit)
 * iSeries_Read_Long = Read Long  (32 bit)
 */
u8 iSeries_Read_Byte(const volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
521
	int retry = 0;
L
Linus Torvalds 已提交
522
	struct HvCallPci_LoadReturn ret;
523
	struct device_node *DevNode =
L
Linus Torvalds 已提交
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Read_Byte: invalid access at IO address %p\n", IoAddress);
		return 0xff;
	}
	do {
		HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, BarOffset, 0);
540
	} while (CheckReturnCode("RDB", DevNode, &retry, ret.rc) != 0);
L
Linus Torvalds 已提交
541 542 543 544 545 546 547 548 549

	return (u8)ret.value;
}
EXPORT_SYMBOL(iSeries_Read_Byte);

u16 iSeries_Read_Word(const volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
550
	int retry = 0;
L
Linus Torvalds 已提交
551
	struct HvCallPci_LoadReturn ret;
552
	struct device_node *DevNode =
L
Linus Torvalds 已提交
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Read_Word: invalid access at IO address %p\n", IoAddress);
		return 0xffff;
	}
	do {
		HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa,
				BarOffset, 0);
570
	} while (CheckReturnCode("RDW", DevNode, &retry, ret.rc) != 0);
L
Linus Torvalds 已提交
571 572 573 574 575 576 577 578 579

	return swab16((u16)ret.value);
}
EXPORT_SYMBOL(iSeries_Read_Word);

u32 iSeries_Read_Long(const volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
580
	int retry = 0;
L
Linus Torvalds 已提交
581
	struct HvCallPci_LoadReturn ret;
582
	struct device_node *DevNode =
L
Linus Torvalds 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Read_Long: invalid access at IO address %p\n", IoAddress);
		return 0xffffffff;
	}
	do {
		HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa,
				BarOffset, 0);
600
	} while (CheckReturnCode("RDL", DevNode, &retry, ret.rc) != 0);
L
Linus Torvalds 已提交
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616

	return swab32((u32)ret.value);
}
EXPORT_SYMBOL(iSeries_Read_Long);

/*
 * Write MM I/O Instructions for the iSeries
 *
 * iSeries_Write_Byte = Write Byte (8 bit)
 * iSeries_Write_Word = Write Word(16 bit)
 * iSeries_Write_Long = Write Long(32 bit)
 */
void iSeries_Write_Byte(u8 data, volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
617
	int retry = 0;
L
Linus Torvalds 已提交
618
	u64 rc;
619
	struct device_node *DevNode =
L
Linus Torvalds 已提交
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Write_Byte: invalid access at IO address %p\n", IoAddress);
		return;
	}
	do {
		rc = HvCall4(HvCallPciBarStore8, dsa, BarOffset, data, 0);
636
	} while (CheckReturnCode("WWB", DevNode, &retry, rc) != 0);
L
Linus Torvalds 已提交
637 638 639 640 641 642 643
}
EXPORT_SYMBOL(iSeries_Write_Byte);

void iSeries_Write_Word(u16 data, volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
644
	int retry = 0;
L
Linus Torvalds 已提交
645
	u64 rc;
646
	struct device_node *DevNode =
L
Linus Torvalds 已提交
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Write_Word: invalid access at IO address %p\n", IoAddress);
		return;
	}
	do {
		rc = HvCall4(HvCallPciBarStore16, dsa, BarOffset, swab16(data), 0);
663
	} while (CheckReturnCode("WWW", DevNode, &retry, rc) != 0);
L
Linus Torvalds 已提交
664 665 666 667 668 669 670
}
EXPORT_SYMBOL(iSeries_Write_Word);

void iSeries_Write_Long(u32 data, volatile void __iomem *IoAddress)
{
	u64 BarOffset;
	u64 dsa;
671
	int retry = 0;
L
Linus Torvalds 已提交
672
	u64 rc;
673
	struct device_node *DevNode =
L
Linus Torvalds 已提交
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
		xlate_iomm_address(IoAddress, &dsa, &BarOffset);

	if (DevNode == NULL) {
		static unsigned long last_jiffies;
		static int num_printed;

		if ((jiffies - last_jiffies) > 60 * HZ) {
			last_jiffies = jiffies;
			num_printed = 0;
		}
		if (num_printed++ < 10)
			printk(KERN_ERR "iSeries_Write_Long: invalid access at IO address %p\n", IoAddress);
		return;
	}
	do {
		rc = HvCall4(HvCallPciBarStore32, dsa, BarOffset, swab32(data), 0);
690
	} while (CheckReturnCode("WWL", DevNode, &retry, rc) != 0);
L
Linus Torvalds 已提交
691 692
}
EXPORT_SYMBOL(iSeries_Write_Long);