| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  |  * Support PCI IO workaround | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  |  *  Copyright (C) 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org> | 
					
						
							|  |  |  |  *		       IBM, Corp. | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  |  *  (C) Copyright 2007-2008 TOSHIBA CORPORATION | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #undef DEBUG
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-27 13:39:01 -04:00
										 |  |  | #include <linux/sched.h>	/* for init_mm */
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | #include <asm/machdep.h>
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #include <asm/pgtable.h>
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | #include <asm/ppc-pci.h>
 | 
					
						
							| 
									
										
										
										
											2011-04-11 21:25:01 +00:00
										 |  |  | #include <asm/io-workarounds.h>
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #define IOWA_MAX_BUS	8
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | static struct iowa_bus iowa_busses[IOWA_MAX_BUS]; | 
					
						
							|  |  |  | static unsigned int iowa_bus_count; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | static struct iowa_bus *iowa_pci_find(unsigned long vaddr, unsigned long paddr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i, j; | 
					
						
							|  |  |  | 	struct resource *res; | 
					
						
							|  |  |  | 	unsigned long vstart, vend; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	for (i = 0; i < iowa_bus_count; i++) { | 
					
						
							|  |  |  | 		struct iowa_bus *bus = &iowa_busses[i]; | 
					
						
							|  |  |  | 		struct pci_controller *phb = bus->phb; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 		if (vaddr) { | 
					
						
							|  |  |  | 			vstart = (unsigned long)phb->io_base_virt; | 
					
						
							|  |  |  | 			vend = vstart + phb->pci_io_size - 1; | 
					
						
							|  |  |  | 			if ((vaddr >= vstart) && (vaddr <= vend)) | 
					
						
							|  |  |  | 				return bus; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (paddr) | 
					
						
							|  |  |  | 			for (j = 0; j < 3; j++) { | 
					
						
							|  |  |  | 				res = &phb->mem_resources[j]; | 
					
						
							|  |  |  | 				if (paddr >= res->start && paddr <= res->end) | 
					
						
							|  |  |  | 					return bus; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #ifdef CONFIG_PPC_INDIRECT_MMIO
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR addr) | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-20 14:30:18 +05:30
										 |  |  | 	unsigned hugepage_shift; | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	struct iowa_bus *bus; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	int token; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	token = PCI_GET_ADDR_TOKEN(addr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	if (token && token <= iowa_bus_count) | 
					
						
							|  |  |  | 		bus = &iowa_busses[token - 1]; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		unsigned long vaddr, paddr; | 
					
						
							|  |  |  | 		pte_t *ptep; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		vaddr = (unsigned long)PCI_FIX_ADDR(addr); | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 		if (vaddr < PHB_IO_BASE || vaddr >= PHB_IO_END) | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-20 14:30:18 +05:30
										 |  |  | 		ptep = find_linux_pte_or_hugepte(init_mm.pgd, vaddr, | 
					
						
							|  |  |  | 						 &hugepage_shift); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 		if (ptep == NULL) | 
					
						
							|  |  |  | 			paddr = 0; | 
					
						
							| 
									
										
										
										
											2013-06-20 14:30:18 +05:30
										 |  |  | 		else { | 
					
						
							|  |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * we don't have hugepages backing iomem | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			WARN_ON(hugepage_shift); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 			paddr = pte_pfn(*ptep) << PAGE_SHIFT; | 
					
						
							| 
									
										
										
										
											2013-06-20 14:30:18 +05:30
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 		bus = iowa_pci_find(vaddr, paddr); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (bus == NULL) | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	return bus; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #else /* CONFIG_PPC_INDIRECT_MMIO */
 | 
					
						
							|  |  |  | struct iowa_bus *iowa_mem_find_bus(const PCI_IO_ADDR addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* !CONFIG_PPC_INDIRECT_MMIO */
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #ifdef CONFIG_PPC_INDIRECT_PIO
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | struct iowa_bus *iowa_pio_find_bus(unsigned long port) | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	unsigned long vaddr = (unsigned long)pci_io_base + port; | 
					
						
							|  |  |  | 	return iowa_pci_find(vaddr, 0); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #else
 | 
					
						
							|  |  |  | struct iowa_bus *iowa_pio_find_bus(unsigned long port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #define DEF_PCI_AC_RET(name, ret, at, al, space, aa)		\
 | 
					
						
							|  |  |  | static ret iowa_##name at					\ | 
					
						
							|  |  |  | {								\ | 
					
						
							|  |  |  | 	struct iowa_bus *bus;					\ | 
					
						
							|  |  |  | 	bus = iowa_##space##_find_bus(aa);			\ | 
					
						
							|  |  |  | 	if (bus && bus->ops && bus->ops->name)			\ | 
					
						
							|  |  |  | 		return bus->ops->name al;			\ | 
					
						
							|  |  |  | 	return __do_##name al;					\ | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #define DEF_PCI_AC_NORET(name, at, al, space, aa)		\
 | 
					
						
							|  |  |  | static void iowa_##name at					\ | 
					
						
							|  |  |  | {								\ | 
					
						
							|  |  |  | 	struct iowa_bus *bus;					\ | 
					
						
							|  |  |  | 	bus = iowa_##space##_find_bus(aa);			\ | 
					
						
							|  |  |  | 	if (bus && bus->ops && bus->ops->name) {		\ | 
					
						
							|  |  |  | 		bus->ops->name al;				\ | 
					
						
							|  |  |  | 		return;						\ | 
					
						
							|  |  |  | 	}							\ | 
					
						
							|  |  |  | 	__do_##name al;						\ | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #include <asm/io-defs.h>
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #undef DEF_PCI_AC_RET
 | 
					
						
							|  |  |  | #undef DEF_PCI_AC_NORET
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static const struct ppc_pci_io iowa_pci_io = { | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #define DEF_PCI_AC_RET(name, ret, at, al, space, aa)	.name = iowa_##name,
 | 
					
						
							|  |  |  | #define DEF_PCI_AC_NORET(name, at, al, space, aa)	.name = iowa_##name,
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #include <asm/io-defs.h>
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | #undef DEF_PCI_AC_RET
 | 
					
						
							|  |  |  | #undef DEF_PCI_AC_NORET
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #ifdef CONFIG_PPC_INDIRECT_MMIO
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:03:44 +00:00
										 |  |  | static void __iomem *iowa_ioremap(phys_addr_t addr, unsigned long size, | 
					
						
							| 
									
										
										
										
											2009-02-22 16:19:14 +00:00
										 |  |  | 				  unsigned long flags, void *caller) | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	struct iowa_bus *bus; | 
					
						
							| 
									
										
										
										
											2009-02-22 16:19:14 +00:00
										 |  |  | 	void __iomem *res = __ioremap_caller(addr, size, flags, caller); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	int busno; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-06 14:03:44 +00:00
										 |  |  | 	bus = iowa_pci_find(0, (unsigned long)addr); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 	if (bus != NULL) { | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 		busno = bus - iowa_busses; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 		PCI_SET_ADDR_TOKEN(res, busno + 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-15 13:03:08 +10:00
										 |  |  | #else /* CONFIG_PPC_INDIRECT_MMIO */
 | 
					
						
							|  |  |  | #define iowa_ioremap NULL
 | 
					
						
							|  |  |  | #endif /* !CONFIG_PPC_INDIRECT_MMIO */
 | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-11 21:25:02 +00:00
										 |  |  | /* Enable IO workaround */ | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static void io_workaround_init(void) | 
					
						
							| 
									
										
										
										
											2011-04-11 21:25:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	static int io_workaround_inited; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (io_workaround_inited) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	ppc_pci_io = iowa_pci_io; | 
					
						
							|  |  |  | 	ppc_md.ioremap = iowa_ioremap; | 
					
						
							|  |  |  | 	io_workaround_inited = 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Register new bus to support workaround */ | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | void iowa_register_bus(struct pci_controller *phb, struct ppc_pci_io *ops, | 
					
						
							|  |  |  | 		       int (*initfunc)(struct iowa_bus *, void *), void *data) | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	struct iowa_bus *bus; | 
					
						
							| 
									
										
										
										
											2007-12-10 14:33:21 +11:00
										 |  |  | 	struct device_node *np = phb->dn; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-11 21:25:02 +00:00
										 |  |  | 	io_workaround_init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	if (iowa_bus_count >= IOWA_MAX_BUS) { | 
					
						
							|  |  |  | 		pr_err("IOWA:Too many pci bridges, " | 
					
						
							|  |  |  | 		       "workarounds disabled for %s\n", np->full_name); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	bus = &iowa_busses[iowa_bus_count]; | 
					
						
							|  |  |  | 	bus->phb = phb; | 
					
						
							|  |  |  | 	bus->ops = ops; | 
					
						
							| 
									
										
										
										
											2011-04-11 21:25:02 +00:00
										 |  |  | 	bus->private = data; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	if (initfunc) | 
					
						
							|  |  |  | 		if ((*initfunc)(bus, data)) | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	iowa_bus_count++; | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 19:21:10 +10:00
										 |  |  | 	pr_debug("IOWA:[%d]Add bus, %s.\n", iowa_bus_count-1, np->full_name); | 
					
						
							| 
									
										
										
										
											2006-11-11 17:25:12 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |