xref: /openbmc/linux/drivers/parisc/lba_pci.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds **
41da177e4SLinus Torvalds **  PCI Lower Bus Adapter (LBA) manager
51da177e4SLinus Torvalds **
61da177e4SLinus Torvalds **	(c) Copyright 1999,2000 Grant Grundler
71da177e4SLinus Torvalds **	(c) Copyright 1999,2000 Hewlett-Packard Company
81da177e4SLinus Torvalds **
91da177e4SLinus Torvalds **
101da177e4SLinus Torvalds **
111da177e4SLinus Torvalds ** This module primarily provides access to PCI bus (config/IOport
121da177e4SLinus Torvalds ** spaces) on platforms with an SBA/LBA chipset. A/B/C/J/L/N-class
131da177e4SLinus Torvalds ** with 4 digit model numbers - eg C3000 (and A400...sigh).
141da177e4SLinus Torvalds **
151da177e4SLinus Torvalds ** LBA driver isn't as simple as the Dino driver because:
161da177e4SLinus Torvalds **   (a) this chip has substantial bug fixes between revisions
171da177e4SLinus Torvalds **       (Only one Dino bug has a software workaround :^(  )
181da177e4SLinus Torvalds **   (b) has more options which we don't (yet) support (DMA hints, OLARD)
191da177e4SLinus Torvalds **   (c) IRQ support lives in the I/O SAPIC driver (not with PCI driver)
201da177e4SLinus Torvalds **   (d) play nicely with both PAT and "Legacy" PA-RISC firmware (PDC).
211da177e4SLinus Torvalds **       (dino only deals with "Legacy" PDC)
221da177e4SLinus Torvalds **
231da177e4SLinus Torvalds ** LBA driver passes the I/O SAPIC HPA to the I/O SAPIC driver.
241da177e4SLinus Torvalds ** (I/O SAPIC is integratd in the LBA chip).
251da177e4SLinus Torvalds **
261da177e4SLinus Torvalds ** FIXME: Add support to SBA and LBA drivers for DMA hint sets
271da177e4SLinus Torvalds ** FIXME: Add support for PCI card hot-plug (OLARD).
281da177e4SLinus Torvalds */
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #include <linux/delay.h>
311da177e4SLinus Torvalds #include <linux/types.h>
321da177e4SLinus Torvalds #include <linux/kernel.h>
331da177e4SLinus Torvalds #include <linux/spinlock.h>
340fe763c5SGreg Kroah-Hartman #include <linux/init.h>		/* for __init */
351da177e4SLinus Torvalds #include <linux/pci.h>
361da177e4SLinus Torvalds #include <linux/ioport.h>
371da177e4SLinus Torvalds #include <linux/slab.h>
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds #include <asm/byteorder.h>
401da177e4SLinus Torvalds #include <asm/pdc.h>
411da177e4SLinus Torvalds #include <asm/pdcpat.h>
421da177e4SLinus Torvalds #include <asm/page.h>
431da177e4SLinus Torvalds 
441790cf91SKyle McMartin #include <asm/ropes.h>
451da177e4SLinus Torvalds #include <asm/hardware.h>	/* for register_parisc_driver() stuff */
461da177e4SLinus Torvalds #include <asm/parisc-device.h>
471da177e4SLinus Torvalds #include <asm/io.h>		/* read/write stuff */
481da177e4SLinus Torvalds 
499b8eeab0SChristoph Hellwig #include "iommu.h"
509b8eeab0SChristoph Hellwig 
511da177e4SLinus Torvalds #undef DEBUG_LBA	/* general stuff */
521da177e4SLinus Torvalds #undef DEBUG_LBA_PORT	/* debug I/O Port access */
531da177e4SLinus Torvalds #undef DEBUG_LBA_CFG	/* debug Config Space Access (ie PCI Bus walk) */
541da177e4SLinus Torvalds #undef DEBUG_LBA_PAT	/* debug PCI Resource Mgt code - PDC PAT only */
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds #undef FBB_SUPPORT	/* Fast Back-Back xfers - NOT READY YET */
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds #ifdef DEBUG_LBA
601da177e4SLinus Torvalds #define DBG(x...)	printk(x)
611da177e4SLinus Torvalds #else
621da177e4SLinus Torvalds #define DBG(x...)
631da177e4SLinus Torvalds #endif
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #ifdef DEBUG_LBA_PORT
661da177e4SLinus Torvalds #define DBG_PORT(x...)	printk(x)
671da177e4SLinus Torvalds #else
681da177e4SLinus Torvalds #define DBG_PORT(x...)
691da177e4SLinus Torvalds #endif
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds #ifdef DEBUG_LBA_CFG
721da177e4SLinus Torvalds #define DBG_CFG(x...)	printk(x)
731da177e4SLinus Torvalds #else
741da177e4SLinus Torvalds #define DBG_CFG(x...)
751da177e4SLinus Torvalds #endif
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds #ifdef DEBUG_LBA_PAT
781da177e4SLinus Torvalds #define DBG_PAT(x...)	printk(x)
791da177e4SLinus Torvalds #else
801da177e4SLinus Torvalds #define DBG_PAT(x...)
811da177e4SLinus Torvalds #endif
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds /*
851da177e4SLinus Torvalds ** Config accessor functions only pass in the 8-bit bus number and not
861da177e4SLinus Torvalds ** the 8-bit "PCI Segment" number. Each LBA will be assigned a PCI bus
871da177e4SLinus Torvalds ** number based on what firmware wrote into the scratch register.
881da177e4SLinus Torvalds **
891da177e4SLinus Torvalds ** The "secondary" bus number is set to this before calling
901da177e4SLinus Torvalds ** pci_register_ops(). If any PPB's are present, the scan will
911da177e4SLinus Torvalds ** discover them and update the "secondary" and "subordinate"
921da177e4SLinus Torvalds ** fields in the pci_bus structure.
931da177e4SLinus Torvalds **
941da177e4SLinus Torvalds ** Changes in the configuration *may* result in a different
951da177e4SLinus Torvalds ** bus number for each LBA depending on what firmware does.
961da177e4SLinus Torvalds */
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds #define MODULE_NAME "LBA"
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds /* non-postable I/O port space, densely packed */
1011da177e4SLinus Torvalds #define LBA_PORT_BASE	(PCI_F_EXTEND | 0xfee00000UL)
1028039de10SHelge Deller static void __iomem *astro_iop_base __read_mostly;
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds static u32 lba_t32;
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /* lba flags */
1071da177e4SLinus Torvalds #define LBA_FLAG_SKIP_PROBE	0x10
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds #define LBA_SKIP_PROBE(d) ((d)->flags & LBA_FLAG_SKIP_PROBE)
1101da177e4SLinus Torvalds 
LBA_DEV(struct pci_hba_data * hba)11150075267SChristoph Hellwig static inline struct lba_device *LBA_DEV(struct pci_hba_data *hba)
11250075267SChristoph Hellwig {
11350075267SChristoph Hellwig 	return container_of(hba, struct lba_device, hba);
11450075267SChristoph Hellwig }
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds /*
1171da177e4SLinus Torvalds ** Only allow 8 subsidiary busses per LBA
1181da177e4SLinus Torvalds ** Problem is the PCI bus numbering is globally shared.
1191da177e4SLinus Torvalds */
1201da177e4SLinus Torvalds #define LBA_MAX_NUM_BUSES 8
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds /************************************
1231da177e4SLinus Torvalds  * LBA register read and write support
1241da177e4SLinus Torvalds  *
1251da177e4SLinus Torvalds  * BE WARNED: register writes are posted.
1261da177e4SLinus Torvalds  *  (ie follow writes which must reach HW with a read)
1271da177e4SLinus Torvalds  */
1281da177e4SLinus Torvalds #define READ_U8(addr)  __raw_readb(addr)
1291da177e4SLinus Torvalds #define READ_U16(addr) __raw_readw(addr)
1301da177e4SLinus Torvalds #define READ_U32(addr) __raw_readl(addr)
1311da177e4SLinus Torvalds #define WRITE_U8(value, addr)  __raw_writeb(value, addr)
1321da177e4SLinus Torvalds #define WRITE_U16(value, addr) __raw_writew(value, addr)
1331da177e4SLinus Torvalds #define WRITE_U32(value, addr) __raw_writel(value, addr)
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds #define READ_REG8(addr)  readb(addr)
1361da177e4SLinus Torvalds #define READ_REG16(addr) readw(addr)
1371da177e4SLinus Torvalds #define READ_REG32(addr) readl(addr)
1381da177e4SLinus Torvalds #define READ_REG64(addr) readq(addr)
1391da177e4SLinus Torvalds #define WRITE_REG8(value, addr)  writeb(value, addr)
1401da177e4SLinus Torvalds #define WRITE_REG16(value, addr) writew(value, addr)
1411da177e4SLinus Torvalds #define WRITE_REG32(value, addr) writel(value, addr)
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds #define LBA_CFG_TOK(bus,dfn) ((u32) ((bus)<<16 | (dfn)<<8))
1451da177e4SLinus Torvalds #define LBA_CFG_BUS(tok)  ((u8) ((tok)>>16))
1461da177e4SLinus Torvalds #define LBA_CFG_DEV(tok)  ((u8) ((tok)>>11) & 0x1f)
1471da177e4SLinus Torvalds #define LBA_CFG_FUNC(tok) ((u8) ((tok)>>8 ) & 0x7)
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds /*
1511da177e4SLinus Torvalds ** Extract LBA (Rope) number from HPA
1521da177e4SLinus Torvalds ** REVISIT: 16 ropes for Stretch/Ike?
1531da177e4SLinus Torvalds */
1541da177e4SLinus Torvalds #define ROPES_PER_IOC	8
1551da177e4SLinus Torvalds #define LBA_NUM(x)    ((((unsigned long) x) >> 13) & (ROPES_PER_IOC-1))
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds static void
lba_dump_res(struct resource * r,int d)1591da177e4SLinus Torvalds lba_dump_res(struct resource *r, int d)
1601da177e4SLinus Torvalds {
1611da177e4SLinus Torvalds 	int i;
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds 	if (NULL == r)
1641da177e4SLinus Torvalds 		return;
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds 	printk(KERN_DEBUG "(%p)", r->parent);
1671da177e4SLinus Torvalds 	for (i = d; i ; --i) printk(" ");
168645d11d4SMatthew Wilcox 	printk(KERN_DEBUG "%p [%lx,%lx]/%lx\n", r,
169645d11d4SMatthew Wilcox 		(long)r->start, (long)r->end, r->flags);
1701da177e4SLinus Torvalds 	lba_dump_res(r->child, d+2);
1711da177e4SLinus Torvalds 	lba_dump_res(r->sibling, d);
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds /*
1761da177e4SLinus Torvalds ** LBA rev 2.0, 2.1, 2.2, and 3.0 bus walks require a complex
1771da177e4SLinus Torvalds ** workaround for cfg cycles:
1781da177e4SLinus Torvalds **	-- preserve  LBA state
1791da177e4SLinus Torvalds **	-- prevent any DMA from occurring
1801da177e4SLinus Torvalds **	-- turn on smart mode
1811da177e4SLinus Torvalds **	-- probe with config writes before doing config reads
1821da177e4SLinus Torvalds **	-- check ERROR_STATUS
1831da177e4SLinus Torvalds **	-- clear ERROR_STATUS
1841da177e4SLinus Torvalds **	-- restore LBA state
1851da177e4SLinus Torvalds **
1861da177e4SLinus Torvalds ** The workaround is only used for device discovery.
1871da177e4SLinus Torvalds */
1881da177e4SLinus Torvalds 
lba_device_present(u8 bus,u8 dfn,struct lba_device * d)1891da177e4SLinus Torvalds static int lba_device_present(u8 bus, u8 dfn, struct lba_device *d)
1901da177e4SLinus Torvalds {
191b918c62eSYinghai Lu 	u8 first_bus = d->hba.hba_bus->busn_res.start;
192b918c62eSYinghai Lu 	u8 last_sub_bus = d->hba.hba_bus->busn_res.end;
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	if ((bus < first_bus) ||
1951da177e4SLinus Torvalds 	    (bus > last_sub_bus) ||
1961da177e4SLinus Torvalds 	    ((bus - first_bus) >= LBA_MAX_NUM_BUSES)) {
1971da177e4SLinus Torvalds 		return 0;
1981da177e4SLinus Torvalds 	}
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 	return 1;
2011da177e4SLinus Torvalds }
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds #define LBA_CFG_SETUP(d, tok) {				\
2061da177e4SLinus Torvalds     /* Save contents of error config register.  */			\
2071da177e4SLinus Torvalds     error_config = READ_REG32(d->hba.base_addr + LBA_ERROR_CONFIG);		\
2081da177e4SLinus Torvalds \
2091da177e4SLinus Torvalds     /* Save contents of status control register.  */			\
2101da177e4SLinus Torvalds     status_control = READ_REG32(d->hba.base_addr + LBA_STAT_CTL);		\
2111da177e4SLinus Torvalds \
2121da177e4SLinus Torvalds     /* For LBA rev 2.0, 2.1, 2.2, and 3.0, we must disable DMA		\
2131da177e4SLinus Torvalds     ** arbitration for full bus walks.					\
2141da177e4SLinus Torvalds     */									\
2151da177e4SLinus Torvalds 	/* Save contents of arb mask register. */			\
2161da177e4SLinus Torvalds 	arb_mask = READ_REG32(d->hba.base_addr + LBA_ARB_MASK);		\
2171da177e4SLinus Torvalds \
2181da177e4SLinus Torvalds 	/*								\
2191da177e4SLinus Torvalds 	 * Turn off all device arbitration bits (i.e. everything	\
2201da177e4SLinus Torvalds 	 * except arbitration enable bit).				\
2211da177e4SLinus Torvalds 	 */								\
2221da177e4SLinus Torvalds 	WRITE_REG32(0x1, d->hba.base_addr + LBA_ARB_MASK);		\
2231da177e4SLinus Torvalds \
2241da177e4SLinus Torvalds     /*									\
2251da177e4SLinus Torvalds      * Set the smart mode bit so that master aborts don't cause		\
2261da177e4SLinus Torvalds      * LBA to go into PCI fatal mode (required).			\
2271da177e4SLinus Torvalds      */									\
2281da177e4SLinus Torvalds     WRITE_REG32(error_config | LBA_SMART_MODE, d->hba.base_addr + LBA_ERROR_CONFIG);	\
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds #define LBA_CFG_PROBE(d, tok) {				\
2331da177e4SLinus Torvalds     /*									\
2341da177e4SLinus Torvalds      * Setup Vendor ID write and read back the address register		\
2351da177e4SLinus Torvalds      * to make sure that LBA is the bus master.				\
2361da177e4SLinus Torvalds      */									\
2371da177e4SLinus Torvalds     WRITE_REG32(tok | PCI_VENDOR_ID, (d)->hba.base_addr + LBA_PCI_CFG_ADDR);\
2381da177e4SLinus Torvalds     /*									\
2391da177e4SLinus Torvalds      * Read address register to ensure that LBA is the bus master,	\
2401da177e4SLinus Torvalds      * which implies that DMA traffic has stopped when DMA arb is off.	\
2411da177e4SLinus Torvalds      */									\
2421da177e4SLinus Torvalds     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);	\
2431da177e4SLinus Torvalds     /*									\
2441da177e4SLinus Torvalds      * Generate a cfg write cycle (will have no affect on		\
2451da177e4SLinus Torvalds      * Vendor ID register since read-only).				\
2461da177e4SLinus Torvalds      */									\
2471da177e4SLinus Torvalds     WRITE_REG32(~0, (d)->hba.base_addr + LBA_PCI_CFG_DATA);		\
2481da177e4SLinus Torvalds     /*									\
2491da177e4SLinus Torvalds      * Make sure write has completed before proceeding further,		\
2501da177e4SLinus Torvalds      * i.e. before setting clear enable.				\
2511da177e4SLinus Torvalds      */									\
2521da177e4SLinus Torvalds     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);	\
2531da177e4SLinus Torvalds }
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds /*
2571da177e4SLinus Torvalds  * HPREVISIT:
2581da177e4SLinus Torvalds  *   -- Can't tell if config cycle got the error.
2591da177e4SLinus Torvalds  *
2601da177e4SLinus Torvalds  *		OV bit is broken until rev 4.0, so can't use OV bit and
2611da177e4SLinus Torvalds  *		LBA_ERROR_LOG_ADDR to tell if error belongs to config cycle.
2621da177e4SLinus Torvalds  *
2631da177e4SLinus Torvalds  *		As of rev 4.0, no longer need the error check.
2641da177e4SLinus Torvalds  *
2651da177e4SLinus Torvalds  *   -- Even if we could tell, we still want to return -1
2661da177e4SLinus Torvalds  *	for **ANY** error (not just master abort).
2671da177e4SLinus Torvalds  *
2681da177e4SLinus Torvalds  *   -- Only clear non-fatal errors (we don't want to bring
2691da177e4SLinus Torvalds  *	LBA out of pci-fatal mode).
2701da177e4SLinus Torvalds  *
2711da177e4SLinus Torvalds  *		Actually, there is still a race in which
2721da177e4SLinus Torvalds  *		we could be clearing a fatal error.  We will
2731da177e4SLinus Torvalds  *		live with this during our initial bus walk
2741da177e4SLinus Torvalds  *		until rev 4.0 (no driver activity during
2751da177e4SLinus Torvalds  *		initial bus walk).  The initial bus walk
2761da177e4SLinus Torvalds  *		has race conditions concerning the use of
2771da177e4SLinus Torvalds  *		smart mode as well.
2781da177e4SLinus Torvalds  */
2791da177e4SLinus Torvalds 
2801da177e4SLinus Torvalds #define LBA_MASTER_ABORT_ERROR 0xc
2811da177e4SLinus Torvalds #define LBA_FATAL_ERROR 0x10
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds #define LBA_CFG_MASTER_ABORT_CHECK(d, base, tok, error) {		\
2841da177e4SLinus Torvalds     u32 error_status = 0;						\
2851da177e4SLinus Torvalds     /*									\
2861da177e4SLinus Torvalds      * Set clear enable (CE) bit. Unset by HW when new			\
2871da177e4SLinus Torvalds      * errors are logged -- LBA HW ERS section 14.3.3).		\
2881da177e4SLinus Torvalds      */									\
2891da177e4SLinus Torvalds     WRITE_REG32(status_control | CLEAR_ERRLOG_ENABLE, base + LBA_STAT_CTL); \
2901da177e4SLinus Torvalds     error_status = READ_REG32(base + LBA_ERROR_STATUS);		\
2911da177e4SLinus Torvalds     if ((error_status & 0x1f) != 0) {					\
2921da177e4SLinus Torvalds 	/*								\
2931da177e4SLinus Torvalds 	 * Fail the config read request.				\
2941da177e4SLinus Torvalds 	 */								\
2951da177e4SLinus Torvalds 	error = 1;							\
2961da177e4SLinus Torvalds 	if ((error_status & LBA_FATAL_ERROR) == 0) {			\
2971da177e4SLinus Torvalds 	    /*								\
2981da177e4SLinus Torvalds 	     * Clear error status (if fatal bit not set) by setting	\
2991da177e4SLinus Torvalds 	     * clear error log bit (CL).				\
3001da177e4SLinus Torvalds 	     */								\
3011da177e4SLinus Torvalds 	    WRITE_REG32(status_control | CLEAR_ERRLOG, base + LBA_STAT_CTL); \
3021da177e4SLinus Torvalds 	}								\
3031da177e4SLinus Torvalds     }									\
3041da177e4SLinus Torvalds }
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds #define LBA_CFG_TR4_ADDR_SETUP(d, addr)					\
3071da177e4SLinus Torvalds 	WRITE_REG32(((addr) & ~3), (d)->hba.base_addr + LBA_PCI_CFG_ADDR);
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds #define LBA_CFG_ADDR_SETUP(d, addr) {					\
3101da177e4SLinus Torvalds     WRITE_REG32(((addr) & ~3), (d)->hba.base_addr + LBA_PCI_CFG_ADDR);	\
3111da177e4SLinus Torvalds     /*									\
3121da177e4SLinus Torvalds      * Read address register to ensure that LBA is the bus master,	\
3131da177e4SLinus Torvalds      * which implies that DMA traffic has stopped when DMA arb is off.	\
3141da177e4SLinus Torvalds      */									\
3151da177e4SLinus Torvalds     lba_t32 = READ_REG32((d)->hba.base_addr + LBA_PCI_CFG_ADDR);	\
3161da177e4SLinus Torvalds }
3171da177e4SLinus Torvalds 
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds #define LBA_CFG_RESTORE(d, base) {					\
3201da177e4SLinus Torvalds     /*									\
3211da177e4SLinus Torvalds      * Restore status control register (turn off clear enable).		\
3221da177e4SLinus Torvalds      */									\
3231da177e4SLinus Torvalds     WRITE_REG32(status_control, base + LBA_STAT_CTL);			\
3241da177e4SLinus Torvalds     /*									\
3251da177e4SLinus Torvalds      * Restore error config register (turn off smart mode).		\
3261da177e4SLinus Torvalds      */									\
3271da177e4SLinus Torvalds     WRITE_REG32(error_config, base + LBA_ERROR_CONFIG);			\
3281da177e4SLinus Torvalds 	/*								\
3291da177e4SLinus Torvalds 	 * Restore arb mask register (reenables DMA arbitration).	\
3301da177e4SLinus Torvalds 	 */								\
3311da177e4SLinus Torvalds 	WRITE_REG32(arb_mask, base + LBA_ARB_MASK);			\
3321da177e4SLinus Torvalds }
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds static unsigned int
lba_rd_cfg(struct lba_device * d,u32 tok,u8 reg,u32 size)3371da177e4SLinus Torvalds lba_rd_cfg(struct lba_device *d, u32 tok, u8 reg, u32 size)
3381da177e4SLinus Torvalds {
3391da177e4SLinus Torvalds 	u32 data = ~0U;
3401da177e4SLinus Torvalds 	int error = 0;
3411da177e4SLinus Torvalds 	u32 arb_mask = 0;	/* used by LBA_CFG_SETUP/RESTORE */
3421da177e4SLinus Torvalds 	u32 error_config = 0;	/* used by LBA_CFG_SETUP/RESTORE */
3431da177e4SLinus Torvalds 	u32 status_control = 0;	/* used by LBA_CFG_SETUP/RESTORE */
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds 	LBA_CFG_SETUP(d, tok);
3461da177e4SLinus Torvalds 	LBA_CFG_PROBE(d, tok);
3471da177e4SLinus Torvalds 	LBA_CFG_MASTER_ABORT_CHECK(d, d->hba.base_addr, tok, error);
3481da177e4SLinus Torvalds 	if (!error) {
3491da177e4SLinus Torvalds 		void __iomem *data_reg = d->hba.base_addr + LBA_PCI_CFG_DATA;
3501da177e4SLinus Torvalds 
3511da177e4SLinus Torvalds 		LBA_CFG_ADDR_SETUP(d, tok | reg);
3521da177e4SLinus Torvalds 		switch (size) {
3531da177e4SLinus Torvalds 		case 1: data = (u32) READ_REG8(data_reg + (reg & 3)); break;
3541da177e4SLinus Torvalds 		case 2: data = (u32) READ_REG16(data_reg+ (reg & 2)); break;
3551da177e4SLinus Torvalds 		case 4: data = READ_REG32(data_reg); break;
3561da177e4SLinus Torvalds 		}
3571da177e4SLinus Torvalds 	}
3581da177e4SLinus Torvalds 	LBA_CFG_RESTORE(d, d->hba.base_addr);
3591da177e4SLinus Torvalds 	return(data);
3601da177e4SLinus Torvalds }
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds 
elroy_cfg_read(struct pci_bus * bus,unsigned int devfn,int pos,int size,u32 * data)3631da177e4SLinus Torvalds static int elroy_cfg_read(struct pci_bus *bus, unsigned int devfn, int pos, int size, u32 *data)
3641da177e4SLinus Torvalds {
3651da177e4SLinus Torvalds 	struct lba_device *d = LBA_DEV(parisc_walk_tree(bus->bridge));
366b918c62eSYinghai Lu 	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
3671da177e4SLinus Torvalds 	u32 tok = LBA_CFG_TOK(local_bus, devfn);
3681da177e4SLinus Torvalds 	void __iomem *data_reg = d->hba.base_addr + LBA_PCI_CFG_DATA;
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	if ((pos > 255) || (devfn > 255))
3711da177e4SLinus Torvalds 		return -EINVAL;
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds /* FIXME: B2K/C3600 workaround is always use old method... */
3741da177e4SLinus Torvalds 	/* if (!LBA_SKIP_PROBE(d)) */ {
3751da177e4SLinus Torvalds 		/* original - Generate config cycle on broken elroy
3761da177e4SLinus Torvalds 		  with risk we will miss PCI bus errors. */
3771da177e4SLinus Torvalds 		*data = lba_rd_cfg(d, tok, pos, size);
378a8043ecbSHarvey Harrison 		DBG_CFG("%s(%x+%2x) -> 0x%x (a)\n", __func__, tok, pos, *data);
3791da177e4SLinus Torvalds 		return 0;
3801da177e4SLinus Torvalds 	}
3811da177e4SLinus Torvalds 
382b918c62eSYinghai Lu 	if (LBA_SKIP_PROBE(d) && !lba_device_present(bus->busn_res.start, devfn, d)) {
383a8043ecbSHarvey Harrison 		DBG_CFG("%s(%x+%2x) -> -1 (b)\n", __func__, tok, pos);
3841da177e4SLinus Torvalds 		/* either don't want to look or know device isn't present. */
3851da177e4SLinus Torvalds 		*data = ~0U;
3861da177e4SLinus Torvalds 		return(0);
3871da177e4SLinus Torvalds 	}
3881da177e4SLinus Torvalds 
3891da177e4SLinus Torvalds 	/* Basic Algorithm
3901da177e4SLinus Torvalds 	** Should only get here on fully working LBA rev.
3911da177e4SLinus Torvalds 	** This is how simple the code should have been.
3921da177e4SLinus Torvalds 	*/
3931da177e4SLinus Torvalds 	LBA_CFG_ADDR_SETUP(d, tok | pos);
3941da177e4SLinus Torvalds 	switch(size) {
3951da177e4SLinus Torvalds 	case 1: *data = READ_REG8 (data_reg + (pos & 3)); break;
3961da177e4SLinus Torvalds 	case 2: *data = READ_REG16(data_reg + (pos & 2)); break;
3971da177e4SLinus Torvalds 	case 4: *data = READ_REG32(data_reg); break;
3981da177e4SLinus Torvalds 	}
399a8043ecbSHarvey Harrison 	DBG_CFG("%s(%x+%2x) -> 0x%x (c)\n", __func__, tok, pos, *data);
4001da177e4SLinus Torvalds 	return 0;
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds 
4041da177e4SLinus Torvalds static void
lba_wr_cfg(struct lba_device * d,u32 tok,u8 reg,u32 data,u32 size)4051da177e4SLinus Torvalds lba_wr_cfg(struct lba_device *d, u32 tok, u8 reg, u32 data, u32 size)
4061da177e4SLinus Torvalds {
4071d72e83dSHelge Deller 	int error __maybe_unused = 0;
4081da177e4SLinus Torvalds 	u32 arb_mask = 0;
4091da177e4SLinus Torvalds 	u32 error_config = 0;
4101da177e4SLinus Torvalds 	u32 status_control = 0;
4111da177e4SLinus Torvalds 	void __iomem *data_reg = d->hba.base_addr + LBA_PCI_CFG_DATA;
4121da177e4SLinus Torvalds 
4131da177e4SLinus Torvalds 	LBA_CFG_SETUP(d, tok);
4141da177e4SLinus Torvalds 	LBA_CFG_ADDR_SETUP(d, tok | reg);
4151da177e4SLinus Torvalds 	switch (size) {
4161da177e4SLinus Torvalds 	case 1: WRITE_REG8 (data, data_reg + (reg & 3)); break;
4171da177e4SLinus Torvalds 	case 2: WRITE_REG16(data, data_reg + (reg & 2)); break;
4181da177e4SLinus Torvalds 	case 4: WRITE_REG32(data, data_reg);             break;
4191da177e4SLinus Torvalds 	}
4201da177e4SLinus Torvalds 	LBA_CFG_MASTER_ABORT_CHECK(d, d->hba.base_addr, tok, error);
4211da177e4SLinus Torvalds 	LBA_CFG_RESTORE(d, d->hba.base_addr);
4221da177e4SLinus Torvalds }
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds /*
4261da177e4SLinus Torvalds  * LBA 4.0 config write code implements non-postable semantics
4271da177e4SLinus Torvalds  * by doing a read of CONFIG ADDR after the write.
4281da177e4SLinus Torvalds  */
4291da177e4SLinus Torvalds 
elroy_cfg_write(struct pci_bus * bus,unsigned int devfn,int pos,int size,u32 data)4301da177e4SLinus Torvalds static int elroy_cfg_write(struct pci_bus *bus, unsigned int devfn, int pos, int size, u32 data)
4311da177e4SLinus Torvalds {
4321da177e4SLinus Torvalds 	struct lba_device *d = LBA_DEV(parisc_walk_tree(bus->bridge));
433b918c62eSYinghai Lu 	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
4341da177e4SLinus Torvalds 	u32 tok = LBA_CFG_TOK(local_bus,devfn);
4351da177e4SLinus Torvalds 
4361da177e4SLinus Torvalds 	if ((pos > 255) || (devfn > 255))
4371da177e4SLinus Torvalds 		return -EINVAL;
4381da177e4SLinus Torvalds 
4391da177e4SLinus Torvalds 	if (!LBA_SKIP_PROBE(d)) {
4401da177e4SLinus Torvalds 		/* Original Workaround */
4411da177e4SLinus Torvalds 		lba_wr_cfg(d, tok, pos, (u32) data, size);
442a8043ecbSHarvey Harrison 		DBG_CFG("%s(%x+%2x) = 0x%x (a)\n", __func__, tok, pos,data);
4431da177e4SLinus Torvalds 		return 0;
4441da177e4SLinus Torvalds 	}
4451da177e4SLinus Torvalds 
446b918c62eSYinghai Lu 	if (LBA_SKIP_PROBE(d) && (!lba_device_present(bus->busn_res.start, devfn, d))) {
447a8043ecbSHarvey Harrison 		DBG_CFG("%s(%x+%2x) = 0x%x (b)\n", __func__, tok, pos,data);
4481da177e4SLinus Torvalds 		return 1; /* New Workaround */
4491da177e4SLinus Torvalds 	}
4501da177e4SLinus Torvalds 
451a8043ecbSHarvey Harrison 	DBG_CFG("%s(%x+%2x) = 0x%x (c)\n", __func__, tok, pos, data);
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds 	/* Basic Algorithm */
4541da177e4SLinus Torvalds 	LBA_CFG_ADDR_SETUP(d, tok | pos);
4551da177e4SLinus Torvalds 	switch(size) {
4561da177e4SLinus Torvalds 	case 1: WRITE_REG8 (data, d->hba.base_addr + LBA_PCI_CFG_DATA + (pos & 3));
4571da177e4SLinus Torvalds 		   break;
4581da177e4SLinus Torvalds 	case 2: WRITE_REG16(data, d->hba.base_addr + LBA_PCI_CFG_DATA + (pos & 2));
4591da177e4SLinus Torvalds 		   break;
4601da177e4SLinus Torvalds 	case 4: WRITE_REG32(data, d->hba.base_addr + LBA_PCI_CFG_DATA);
4611da177e4SLinus Torvalds 		   break;
4621da177e4SLinus Torvalds 	}
4631da177e4SLinus Torvalds 	/* flush posted write */
4641da177e4SLinus Torvalds 	lba_t32 = READ_REG32(d->hba.base_addr + LBA_PCI_CFG_ADDR);
4651da177e4SLinus Torvalds 	return 0;
4661da177e4SLinus Torvalds }
4671da177e4SLinus Torvalds 
4681da177e4SLinus Torvalds 
4691da177e4SLinus Torvalds static struct pci_ops elroy_cfg_ops = {
4701da177e4SLinus Torvalds 	.read =		elroy_cfg_read,
4711da177e4SLinus Torvalds 	.write =	elroy_cfg_write,
4721da177e4SLinus Torvalds };
4731da177e4SLinus Torvalds 
4741da177e4SLinus Torvalds /*
4751da177e4SLinus Torvalds  * The mercury_cfg_ops are slightly misnamed; they're also used for Elroy
4761da177e4SLinus Torvalds  * TR4.0 as no additional bugs were found in this areea between Elroy and
4771da177e4SLinus Torvalds  * Mercury
4781da177e4SLinus Torvalds  */
4791da177e4SLinus Torvalds 
mercury_cfg_read(struct pci_bus * bus,unsigned int devfn,int pos,int size,u32 * data)4801da177e4SLinus Torvalds static int mercury_cfg_read(struct pci_bus *bus, unsigned int devfn, int pos, int size, u32 *data)
4811da177e4SLinus Torvalds {
4821da177e4SLinus Torvalds 	struct lba_device *d = LBA_DEV(parisc_walk_tree(bus->bridge));
483b918c62eSYinghai Lu 	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
4841da177e4SLinus Torvalds 	u32 tok = LBA_CFG_TOK(local_bus, devfn);
4851da177e4SLinus Torvalds 	void __iomem *data_reg = d->hba.base_addr + LBA_PCI_CFG_DATA;
4861da177e4SLinus Torvalds 
4871da177e4SLinus Torvalds 	if ((pos > 255) || (devfn > 255))
4881da177e4SLinus Torvalds 		return -EINVAL;
4891da177e4SLinus Torvalds 
4901da177e4SLinus Torvalds 	LBA_CFG_TR4_ADDR_SETUP(d, tok | pos);
4911da177e4SLinus Torvalds 	switch(size) {
4921da177e4SLinus Torvalds 	case 1:
4931da177e4SLinus Torvalds 		*data = READ_REG8(data_reg + (pos & 3));
4941da177e4SLinus Torvalds 		break;
4951da177e4SLinus Torvalds 	case 2:
4961da177e4SLinus Torvalds 		*data = READ_REG16(data_reg + (pos & 2));
4971da177e4SLinus Torvalds 		break;
4981da177e4SLinus Torvalds 	case 4:
4991da177e4SLinus Torvalds 		*data = READ_REG32(data_reg);             break;
5001da177e4SLinus Torvalds 		break;
5011da177e4SLinus Torvalds 	}
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds 	DBG_CFG("mercury_cfg_read(%x+%2x) -> 0x%x\n", tok, pos, *data);
5041da177e4SLinus Torvalds 	return 0;
5051da177e4SLinus Torvalds }
5061da177e4SLinus Torvalds 
5071da177e4SLinus Torvalds /*
5081da177e4SLinus Torvalds  * LBA 4.0 config write code implements non-postable semantics
5091da177e4SLinus Torvalds  * by doing a read of CONFIG ADDR after the write.
5101da177e4SLinus Torvalds  */
5111da177e4SLinus Torvalds 
mercury_cfg_write(struct pci_bus * bus,unsigned int devfn,int pos,int size,u32 data)5121da177e4SLinus Torvalds static int mercury_cfg_write(struct pci_bus *bus, unsigned int devfn, int pos, int size, u32 data)
5131da177e4SLinus Torvalds {
5141da177e4SLinus Torvalds 	struct lba_device *d = LBA_DEV(parisc_walk_tree(bus->bridge));
5151da177e4SLinus Torvalds 	void __iomem *data_reg = d->hba.base_addr + LBA_PCI_CFG_DATA;
516b918c62eSYinghai Lu 	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
5171da177e4SLinus Torvalds 	u32 tok = LBA_CFG_TOK(local_bus,devfn);
5181da177e4SLinus Torvalds 
5191da177e4SLinus Torvalds 	if ((pos > 255) || (devfn > 255))
5201da177e4SLinus Torvalds 		return -EINVAL;
5211da177e4SLinus Torvalds 
522a8043ecbSHarvey Harrison 	DBG_CFG("%s(%x+%2x) <- 0x%x (c)\n", __func__, tok, pos, data);
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds 	LBA_CFG_TR4_ADDR_SETUP(d, tok | pos);
5251da177e4SLinus Torvalds 	switch(size) {
5261da177e4SLinus Torvalds 	case 1:
5271da177e4SLinus Torvalds 		WRITE_REG8 (data, data_reg + (pos & 3));
5281da177e4SLinus Torvalds 		break;
5291da177e4SLinus Torvalds 	case 2:
5301da177e4SLinus Torvalds 		WRITE_REG16(data, data_reg + (pos & 2));
5311da177e4SLinus Torvalds 		break;
5321da177e4SLinus Torvalds 	case 4:
5331da177e4SLinus Torvalds 		WRITE_REG32(data, data_reg);
5341da177e4SLinus Torvalds 		break;
5351da177e4SLinus Torvalds 	}
5361da177e4SLinus Torvalds 
5371da177e4SLinus Torvalds 	/* flush posted write */
5381da177e4SLinus Torvalds 	lba_t32 = READ_U32(d->hba.base_addr + LBA_PCI_CFG_ADDR);
5391da177e4SLinus Torvalds 	return 0;
5401da177e4SLinus Torvalds }
5411da177e4SLinus Torvalds 
5421da177e4SLinus Torvalds static struct pci_ops mercury_cfg_ops = {
5431da177e4SLinus Torvalds 	.read =		mercury_cfg_read,
5441da177e4SLinus Torvalds 	.write =	mercury_cfg_write,
5451da177e4SLinus Torvalds };
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds static void
lba_bios_init(void)5491da177e4SLinus Torvalds lba_bios_init(void)
5501da177e4SLinus Torvalds {
5511da177e4SLinus Torvalds 	DBG(MODULE_NAME ": lba_bios_init\n");
5521da177e4SLinus Torvalds }
5531da177e4SLinus Torvalds 
5541da177e4SLinus Torvalds 
5551da177e4SLinus Torvalds #ifdef CONFIG_64BIT
5561da177e4SLinus Torvalds 
5571da177e4SLinus Torvalds /*
5586ca45a24SGrant Grundler  * truncate_pat_collision:  Deal with overlaps or outright collisions
5596ca45a24SGrant Grundler  *			between PAT PDC reported ranges.
5606ca45a24SGrant Grundler  *
5616ca45a24SGrant Grundler  *   Broken PA8800 firmware will report lmmio range that
5626ca45a24SGrant Grundler  *   overlaps with CPU HPA. Just truncate the lmmio range.
5636ca45a24SGrant Grundler  *
5646ca45a24SGrant Grundler  *   BEWARE: conflicts with this lmmio range may be an
5656ca45a24SGrant Grundler  *   elmmio range which is pointing down another rope.
5666ca45a24SGrant Grundler  *
5676ca45a24SGrant Grundler  *  FIXME: only deals with one collision per range...theoretically we
5686ca45a24SGrant Grundler  *  could have several. Supporting more than one collision will get messy.
5696ca45a24SGrant Grundler  */
5706ca45a24SGrant Grundler static unsigned long
truncate_pat_collision(struct resource * root,struct resource * new)5716ca45a24SGrant Grundler truncate_pat_collision(struct resource *root, struct resource *new)
5726ca45a24SGrant Grundler {
5736ca45a24SGrant Grundler 	unsigned long start = new->start;
5746ca45a24SGrant Grundler 	unsigned long end = new->end;
5756ca45a24SGrant Grundler 	struct resource *tmp = root->child;
5766ca45a24SGrant Grundler 
5776ca45a24SGrant Grundler 	if (end <= start || start < root->start || !tmp)
5786ca45a24SGrant Grundler 		return 0;
5796ca45a24SGrant Grundler 
5806ca45a24SGrant Grundler 	/* find first overlap */
5816ca45a24SGrant Grundler 	while (tmp && tmp->end < start)
5826ca45a24SGrant Grundler 		tmp = tmp->sibling;
5836ca45a24SGrant Grundler 
5846ca45a24SGrant Grundler 	/* no entries overlap */
5856ca45a24SGrant Grundler 	if (!tmp)  return 0;
5866ca45a24SGrant Grundler 
5876ca45a24SGrant Grundler 	/* found one that starts behind the new one
5886ca45a24SGrant Grundler 	** Don't need to do anything.
5896ca45a24SGrant Grundler 	*/
5906ca45a24SGrant Grundler 	if (tmp->start >= end) return 0;
5916ca45a24SGrant Grundler 
5926ca45a24SGrant Grundler 	if (tmp->start <= start) {
5936ca45a24SGrant Grundler 		/* "front" of new one overlaps */
5946ca45a24SGrant Grundler 		new->start = tmp->end + 1;
5956ca45a24SGrant Grundler 
5966ca45a24SGrant Grundler 		if (tmp->end >= end) {
5976ca45a24SGrant Grundler 			/* AACCKK! totally overlaps! drop this range. */
5986ca45a24SGrant Grundler 			return 1;
5996ca45a24SGrant Grundler 		}
6006ca45a24SGrant Grundler 	}
6016ca45a24SGrant Grundler 
6026ca45a24SGrant Grundler 	if (tmp->end < end ) {
6036ca45a24SGrant Grundler 		/* "end" of new one overlaps */
6046ca45a24SGrant Grundler 		new->end = tmp->start - 1;
6056ca45a24SGrant Grundler 	}
6066ca45a24SGrant Grundler 
6076ca45a24SGrant Grundler 	printk(KERN_WARNING "LBA: Truncating lmmio_space [%lx/%lx] "
6086ca45a24SGrant Grundler 					"to [%lx,%lx]\n",
6096ca45a24SGrant Grundler 			start, end,
610645d11d4SMatthew Wilcox 			(long)new->start, (long)new->end );
6116ca45a24SGrant Grundler 
6126ca45a24SGrant Grundler 	return 0;	/* truncation successful */
6136ca45a24SGrant Grundler }
6146ca45a24SGrant Grundler 
615dac76f1bSHelge Deller /*
616dac76f1bSHelge Deller  * extend_lmmio_len: extend lmmio range to maximum length
617dac76f1bSHelge Deller  *
618dac76f1bSHelge Deller  * This is needed at least on C8000 systems to get the ATI FireGL card
619dac76f1bSHelge Deller  * working. On other systems we will currently not extend the lmmio space.
620dac76f1bSHelge Deller  */
621dac76f1bSHelge Deller static unsigned long
extend_lmmio_len(unsigned long start,unsigned long end,unsigned long lba_len)622dac76f1bSHelge Deller extend_lmmio_len(unsigned long start, unsigned long end, unsigned long lba_len)
623dac76f1bSHelge Deller {
624dac76f1bSHelge Deller 	struct resource *tmp;
625dac76f1bSHelge Deller 
626b696e5e9SHelge Deller 	/* exit if not a C8000 */
627b696e5e9SHelge Deller 	if (boot_cpu_data.cpu_type < mako)
628b696e5e9SHelge Deller 		return end;
629b696e5e9SHelge Deller 
630dac76f1bSHelge Deller 	pr_debug("LMMIO mismatch: PAT length = 0x%lx, MASK register = 0x%lx\n",
631dac76f1bSHelge Deller 		end - start, lba_len);
632dac76f1bSHelge Deller 
633dac76f1bSHelge Deller 	lba_len = min(lba_len+1, 256UL*1024*1024); /* limit to 256 MB */
634dac76f1bSHelge Deller 
635dac76f1bSHelge Deller 	pr_debug("LBA: lmmio_space [0x%lx-0x%lx] - original\n", start, end);
636dac76f1bSHelge Deller 
637dac76f1bSHelge Deller 
638dac76f1bSHelge Deller 	end += lba_len;
639dac76f1bSHelge Deller 	if (end < start) /* fix overflow */
640dac76f1bSHelge Deller 		end = -1ULL;
641dac76f1bSHelge Deller 
642dac76f1bSHelge Deller 	pr_debug("LBA: lmmio_space [0x%lx-0x%lx] - current\n", start, end);
643dac76f1bSHelge Deller 
644dac76f1bSHelge Deller 	/* first overlap */
645dac76f1bSHelge Deller 	for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
646dac76f1bSHelge Deller 		pr_debug("LBA: testing %pR\n", tmp);
647dac76f1bSHelge Deller 		if (tmp->start == start)
648dac76f1bSHelge Deller 			continue; /* ignore ourself */
649dac76f1bSHelge Deller 		if (tmp->end < start)
650dac76f1bSHelge Deller 			continue;
651dac76f1bSHelge Deller 		if (tmp->start > end)
652dac76f1bSHelge Deller 			continue;
653dac76f1bSHelge Deller 		if (end >= tmp->start)
654dac76f1bSHelge Deller 			end = tmp->start - 1;
655dac76f1bSHelge Deller 	}
656dac76f1bSHelge Deller 
657dac76f1bSHelge Deller 	pr_info("LBA: lmmio_space [0x%lx-0x%lx] - new\n", start, end);
658dac76f1bSHelge Deller 
659dac76f1bSHelge Deller 	/* return new end */
660dac76f1bSHelge Deller 	return end;
661dac76f1bSHelge Deller }
662dac76f1bSHelge Deller 
6636ca45a24SGrant Grundler #else
6646ca45a24SGrant Grundler #define truncate_pat_collision(r,n)  (0)
6656ca45a24SGrant Grundler #endif
6666ca45a24SGrant Grundler 
pcibios_allocate_bridge_resources(struct pci_dev * dev)667d81f7344SHelge Deller static void pcibios_allocate_bridge_resources(struct pci_dev *dev)
668d81f7344SHelge Deller {
669d81f7344SHelge Deller 	int idx;
670d81f7344SHelge Deller 	struct resource *r;
671d81f7344SHelge Deller 
672d81f7344SHelge Deller 	for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
673d81f7344SHelge Deller 		r = &dev->resource[idx];
674d81f7344SHelge Deller 		if (!r->flags)
675d81f7344SHelge Deller 			continue;
676d81f7344SHelge Deller 		if (r->parent)	/* Already allocated */
677d81f7344SHelge Deller 			continue;
678d81f7344SHelge Deller 		if (!r->start || pci_claim_bridge_resource(dev, idx) < 0) {
679d81f7344SHelge Deller 			/*
680d81f7344SHelge Deller 			 * Something is wrong with the region.
681d81f7344SHelge Deller 			 * Invalidate the resource to prevent
682d81f7344SHelge Deller 			 * child resource allocations in this
683d81f7344SHelge Deller 			 * range.
684d81f7344SHelge Deller 			 */
685d81f7344SHelge Deller 			r->start = r->end = 0;
686d81f7344SHelge Deller 			r->flags = 0;
687d81f7344SHelge Deller 		}
688d81f7344SHelge Deller 	}
689d81f7344SHelge Deller }
690d81f7344SHelge Deller 
pcibios_allocate_bus_resources(struct pci_bus * bus)691d81f7344SHelge Deller static void pcibios_allocate_bus_resources(struct pci_bus *bus)
692d81f7344SHelge Deller {
693d81f7344SHelge Deller 	struct pci_bus *child;
694d81f7344SHelge Deller 
695d81f7344SHelge Deller 	/* Depth-First Search on bus tree */
696d81f7344SHelge Deller 	if (bus->self)
697d81f7344SHelge Deller 		pcibios_allocate_bridge_resources(bus->self);
698d81f7344SHelge Deller 	list_for_each_entry(child, &bus->children, node)
699d81f7344SHelge Deller 		pcibios_allocate_bus_resources(child);
700d81f7344SHelge Deller }
701d81f7344SHelge Deller 
702d81f7344SHelge Deller 
7036ca45a24SGrant Grundler /*
7041da177e4SLinus Torvalds ** The algorithm is generic code.
7051da177e4SLinus Torvalds ** But it needs to access local data structures to get the IRQ base.
7061da177e4SLinus Torvalds ** Could make this a "pci_fixup_irq(bus, region)" but not sure
7071da177e4SLinus Torvalds ** it's worth it.
7081da177e4SLinus Torvalds **
7091da177e4SLinus Torvalds ** Called by do_pci_scan_bus() immediately after each PCI bus is walked.
7101da177e4SLinus Torvalds ** Resources aren't allocated until recursive buswalk below HBA is completed.
7111da177e4SLinus Torvalds */
7121da177e4SLinus Torvalds static void
lba_fixup_bus(struct pci_bus * bus)7131da177e4SLinus Torvalds lba_fixup_bus(struct pci_bus *bus)
7141da177e4SLinus Torvalds {
715f5725f4dSBjorn Helgaas 	struct pci_dev *dev;
7161da177e4SLinus Torvalds #ifdef FBB_SUPPORT
7171da177e4SLinus Torvalds 	u16 status;
7181da177e4SLinus Torvalds #endif
7191da177e4SLinus Torvalds 	struct lba_device *ldev = LBA_DEV(parisc_walk_tree(bus->bridge));
7201da177e4SLinus Torvalds 
7211da177e4SLinus Torvalds 	DBG("lba_fixup_bus(0x%p) bus %d platform_data 0x%p\n",
722b918c62eSYinghai Lu 		bus, (int)bus->busn_res.start, bus->bridge->platform_data);
7231da177e4SLinus Torvalds 
7241da177e4SLinus Torvalds 	/*
7251da177e4SLinus Torvalds 	** Properly Setup MMIO resources for this bus.
7261da177e4SLinus Torvalds 	** pci_alloc_primary_bus() mangles this.
7271da177e4SLinus Torvalds 	*/
7289785d646SGrant Grundler 	if (bus->parent) {
7291da177e4SLinus Torvalds 		/* PCI-PCI Bridge */
730237865f1SBjorn Helgaas 		pci_read_bridge_bases(bus);
731d81f7344SHelge Deller 
732d81f7344SHelge Deller 		/* check and allocate bridge resources */
733d81f7344SHelge Deller 		pcibios_allocate_bus_resources(bus);
7341da177e4SLinus Torvalds 	} else {
7351da177e4SLinus Torvalds 		/* Host-PCI Bridge */
736dc7dce28SBjorn Helgaas 		int err;
7371da177e4SLinus Torvalds 
7381da177e4SLinus Torvalds 		DBG("lba_fixup_bus() %s [%lx/%lx]/%lx\n",
7391da177e4SLinus Torvalds 			ldev->hba.io_space.name,
7401da177e4SLinus Torvalds 			ldev->hba.io_space.start, ldev->hba.io_space.end,
7411da177e4SLinus Torvalds 			ldev->hba.io_space.flags);
7421da177e4SLinus Torvalds 		DBG("lba_fixup_bus() %s [%lx/%lx]/%lx\n",
7431da177e4SLinus Torvalds 			ldev->hba.lmmio_space.name,
7441da177e4SLinus Torvalds 			ldev->hba.lmmio_space.start, ldev->hba.lmmio_space.end,
7451da177e4SLinus Torvalds 			ldev->hba.lmmio_space.flags);
7461da177e4SLinus Torvalds 
7471da177e4SLinus Torvalds 		err = request_resource(&ioport_resource, &(ldev->hba.io_space));
7481da177e4SLinus Torvalds 		if (err < 0) {
7491da177e4SLinus Torvalds 			lba_dump_res(&ioport_resource, 2);
7501da177e4SLinus Torvalds 			BUG();
7511da177e4SLinus Torvalds 		}
7521da177e4SLinus Torvalds 
753b204a4d2SHelge Deller 		if (ldev->hba.elmmio_space.flags) {
7541da177e4SLinus Torvalds 			err = request_resource(&iomem_resource,
7551da177e4SLinus Torvalds 					&(ldev->hba.elmmio_space));
7561da177e4SLinus Torvalds 			if (err < 0) {
7571da177e4SLinus Torvalds 
7581da177e4SLinus Torvalds 				printk("FAILED: lba_fixup_bus() request for "
7591da177e4SLinus Torvalds 						"elmmio_space [%lx/%lx]\n",
760645d11d4SMatthew Wilcox 						(long)ldev->hba.elmmio_space.start,
761645d11d4SMatthew Wilcox 						(long)ldev->hba.elmmio_space.end);
7621da177e4SLinus Torvalds 
7631da177e4SLinus Torvalds 				/* lba_dump_res(&iomem_resource, 2); */
7641da177e4SLinus Torvalds 				/* BUG(); */
765dc7dce28SBjorn Helgaas 			}
7661da177e4SLinus Torvalds 		}
7671da177e4SLinus Torvalds 
768f4d9ea9aSBjorn Helgaas 		if (ldev->hba.lmmio_space.flags) {
7691da177e4SLinus Torvalds 			err = request_resource(&iomem_resource, &(ldev->hba.lmmio_space));
7701da177e4SLinus Torvalds 			if (err < 0) {
7716ca45a24SGrant Grundler 				printk(KERN_ERR "FAILED: lba_fixup_bus() request for "
7721da177e4SLinus Torvalds 					"lmmio_space [%lx/%lx]\n",
773645d11d4SMatthew Wilcox 					(long)ldev->hba.lmmio_space.start,
774645d11d4SMatthew Wilcox 					(long)ldev->hba.lmmio_space.end);
775dc7dce28SBjorn Helgaas 			}
7761da177e4SLinus Torvalds 		}
7771da177e4SLinus Torvalds 
7781da177e4SLinus Torvalds #ifdef CONFIG_64BIT
7791da177e4SLinus Torvalds 		/* GMMIO is  distributed range. Every LBA/Rope gets part it. */
7801da177e4SLinus Torvalds 		if (ldev->hba.gmmio_space.flags) {
7811da177e4SLinus Torvalds 			err = request_resource(&iomem_resource, &(ldev->hba.gmmio_space));
7821da177e4SLinus Torvalds 			if (err < 0) {
7831da177e4SLinus Torvalds 				printk("FAILED: lba_fixup_bus() request for "
7841da177e4SLinus Torvalds 					"gmmio_space [%lx/%lx]\n",
785645d11d4SMatthew Wilcox 					(long)ldev->hba.gmmio_space.start,
786645d11d4SMatthew Wilcox 					(long)ldev->hba.gmmio_space.end);
7871da177e4SLinus Torvalds 				lba_dump_res(&iomem_resource, 2);
7881da177e4SLinus Torvalds 				BUG();
7891da177e4SLinus Torvalds 			}
7901da177e4SLinus Torvalds 		}
7911da177e4SLinus Torvalds #endif
7921da177e4SLinus Torvalds 
7931da177e4SLinus Torvalds 	}
7941da177e4SLinus Torvalds 
7950b79ca2aSBjorn Helgaas 	list_for_each_entry(dev, &bus->devices, bus_list) {
7961da177e4SLinus Torvalds 		int i;
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds 		DBG("lba_fixup_bus() %s\n", pci_name(dev));
7991da177e4SLinus Torvalds 
8001da177e4SLinus Torvalds 		/* Virtualize Device/Bridge Resources. */
8011da177e4SLinus Torvalds 		for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) {
8021da177e4SLinus Torvalds 			struct resource *res = &dev->resource[i];
8031da177e4SLinus Torvalds 
8041da177e4SLinus Torvalds 			/* If resource not allocated - skip it */
8051da177e4SLinus Torvalds 			if (!res->start)
8061da177e4SLinus Torvalds 				continue;
8071da177e4SLinus Torvalds 
80884f4506cSKyle McMartin 			/*
80984f4506cSKyle McMartin 			** FIXME: this will result in whinging for devices
81084f4506cSKyle McMartin 			** that share expansion ROMs (think quad tulip), but
81184f4506cSKyle McMartin 			** isn't harmful.
81284f4506cSKyle McMartin 			*/
8139611f61eSMatthew Wilcox 			pci_claim_resource(dev, i);
8141da177e4SLinus Torvalds 		}
8151da177e4SLinus Torvalds 
8161da177e4SLinus Torvalds #ifdef FBB_SUPPORT
8171da177e4SLinus Torvalds 		/*
8181da177e4SLinus Torvalds 		** If one device does not support FBB transfers,
8191da177e4SLinus Torvalds 		** No one on the bus can be allowed to use them.
8201da177e4SLinus Torvalds 		*/
8211da177e4SLinus Torvalds 		(void) pci_read_config_word(dev, PCI_STATUS, &status);
8221da177e4SLinus Torvalds 		bus->bridge_ctl &= ~(status & PCI_STATUS_FAST_BACK);
8231da177e4SLinus Torvalds #endif
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds                 /*
8261da177e4SLinus Torvalds 		** P2PB's have no IRQs. ignore them.
8271da177e4SLinus Torvalds 		*/
828602c9c9aSHelge Deller 		if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
829602c9c9aSHelge Deller 			pcibios_init_bridge(dev);
8301da177e4SLinus Torvalds 			continue;
831602c9c9aSHelge Deller 		}
8321da177e4SLinus Torvalds 
8331da177e4SLinus Torvalds 		/* Adjust INTERRUPT_LINE for this dev */
8341da177e4SLinus Torvalds 		iosapic_fixup_irq(ldev->iosapic_obj, dev);
8351da177e4SLinus Torvalds 	}
8361da177e4SLinus Torvalds 
8371da177e4SLinus Torvalds #ifdef FBB_SUPPORT
8381da177e4SLinus Torvalds /* FIXME/REVISIT - finish figuring out to set FBB on both
8391da177e4SLinus Torvalds ** pci_setup_bridge() clobbers PCI_BRIDGE_CONTROL.
8401da177e4SLinus Torvalds ** Can't fixup here anyway....garr...
8411da177e4SLinus Torvalds */
8421da177e4SLinus Torvalds 	if (fbb_enable) {
8439785d646SGrant Grundler 		if (bus->parent) {
8441da177e4SLinus Torvalds 			u8 control;
8451da177e4SLinus Torvalds 			/* enable on PPB */
8461da177e4SLinus Torvalds 			(void) pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &control);
8471da177e4SLinus Torvalds 			(void) pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, control | PCI_STATUS_FAST_BACK);
8481da177e4SLinus Torvalds 
8491da177e4SLinus Torvalds 		} else {
8501da177e4SLinus Torvalds 			/* enable on LBA */
8511da177e4SLinus Torvalds 		}
8521da177e4SLinus Torvalds 		fbb_enable = PCI_COMMAND_FAST_BACK;
8531da177e4SLinus Torvalds 	}
8541da177e4SLinus Torvalds 
8551da177e4SLinus Torvalds 	/* Lastly enable FBB/PERR/SERR on all devices too */
8560b79ca2aSBjorn Helgaas 	list_for_each_entry(dev, &bus->devices, bus_list) {
8571da177e4SLinus Torvalds 		(void) pci_read_config_word(dev, PCI_COMMAND, &status);
8581da177e4SLinus Torvalds 		status |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR | fbb_enable;
8591da177e4SLinus Torvalds 		(void) pci_write_config_word(dev, PCI_COMMAND, status);
8601da177e4SLinus Torvalds 	}
8611da177e4SLinus Torvalds #endif
8621da177e4SLinus Torvalds }
8631da177e4SLinus Torvalds 
8641da177e4SLinus Torvalds 
865df8e5bc6SAdrian Bunk static struct pci_bios_ops lba_bios_ops = {
8661da177e4SLinus Torvalds 	.init =		lba_bios_init,
8671da177e4SLinus Torvalds 	.fixup_bus =	lba_fixup_bus,
8681da177e4SLinus Torvalds };
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds 
8721da177e4SLinus Torvalds 
8731da177e4SLinus Torvalds /*******************************************************
8741da177e4SLinus Torvalds **
8751da177e4SLinus Torvalds ** LBA Sprockets "I/O Port" Space Accessor Functions
8761da177e4SLinus Torvalds **
8771da177e4SLinus Torvalds ** This set of accessor functions is intended for use with
8781da177e4SLinus Torvalds ** "legacy firmware" (ie Sprockets on Allegro/Forte boxes).
8791da177e4SLinus Torvalds **
8801da177e4SLinus Torvalds ** Many PCI devices don't require use of I/O port space (eg Tulip,
8811da177e4SLinus Torvalds ** NCR720) since they export the same registers to both MMIO and
8821da177e4SLinus Torvalds ** I/O port space. In general I/O port space is slower than
8831da177e4SLinus Torvalds ** MMIO since drivers are designed so PIO writes can be posted.
8841da177e4SLinus Torvalds **
8851da177e4SLinus Torvalds ********************************************************/
8861da177e4SLinus Torvalds 
8871da177e4SLinus Torvalds #define LBA_PORT_IN(size, mask) \
8881da177e4SLinus Torvalds static u##size lba_astro_in##size (struct pci_hba_data *d, u16 addr) \
8891da177e4SLinus Torvalds { \
8901da177e4SLinus Torvalds 	u##size t; \
8911da177e4SLinus Torvalds 	t = READ_REG##size(astro_iop_base + addr); \
8921da177e4SLinus Torvalds 	DBG_PORT(" 0x%x\n", t); \
8931da177e4SLinus Torvalds 	return (t); \
8941da177e4SLinus Torvalds }
8951da177e4SLinus Torvalds 
8961da177e4SLinus Torvalds LBA_PORT_IN( 8, 3)
8971da177e4SLinus Torvalds LBA_PORT_IN(16, 2)
8981da177e4SLinus Torvalds LBA_PORT_IN(32, 0)
8991da177e4SLinus Torvalds 
9001da177e4SLinus Torvalds 
9011da177e4SLinus Torvalds 
9021da177e4SLinus Torvalds /*
9031da177e4SLinus Torvalds ** BUG X4107:  Ordering broken - DMA RD return can bypass PIO WR
9041da177e4SLinus Torvalds **
9051da177e4SLinus Torvalds ** Fixed in Elroy 2.2. The READ_U32(..., LBA_FUNC_ID) below is
9061da177e4SLinus Torvalds ** guarantee non-postable completion semantics - not avoid X4107.
9071da177e4SLinus Torvalds ** The READ_U32 only guarantees the write data gets to elroy but
9081da177e4SLinus Torvalds ** out to the PCI bus. We can't read stuff from I/O port space
9091da177e4SLinus Torvalds ** since we don't know what has side-effects. Attempting to read
9101da177e4SLinus Torvalds ** from configuration space would be suicidal given the number of
9111da177e4SLinus Torvalds ** bugs in that elroy functionality.
9121da177e4SLinus Torvalds **
9131da177e4SLinus Torvalds **      Description:
9141da177e4SLinus Torvalds **          DMA read results can improperly pass PIO writes (X4107).  The
9151da177e4SLinus Torvalds **          result of this bug is that if a processor modifies a location in
9161da177e4SLinus Torvalds **          memory after having issued PIO writes, the PIO writes are not
9171da177e4SLinus Torvalds **          guaranteed to be completed before a PCI device is allowed to see
9181da177e4SLinus Torvalds **          the modified data in a DMA read.
9191da177e4SLinus Torvalds **
9201da177e4SLinus Torvalds **          Note that IKE bug X3719 in TR1 IKEs will result in the same
9211da177e4SLinus Torvalds **          symptom.
9221da177e4SLinus Torvalds **
9231da177e4SLinus Torvalds **      Workaround:
9241da177e4SLinus Torvalds **          The workaround for this bug is to always follow a PIO write with
9251da177e4SLinus Torvalds **          a PIO read to the same bus before starting DMA on that PCI bus.
9261da177e4SLinus Torvalds **
9271da177e4SLinus Torvalds */
9281da177e4SLinus Torvalds #define LBA_PORT_OUT(size, mask) \
9291da177e4SLinus Torvalds static void lba_astro_out##size (struct pci_hba_data *d, u16 addr, u##size val) \
9301da177e4SLinus Torvalds { \
931a8043ecbSHarvey Harrison 	DBG_PORT("%s(0x%p, 0x%x, 0x%x)\n", __func__, d, addr, val); \
9321da177e4SLinus Torvalds 	WRITE_REG##size(val, astro_iop_base + addr); \
9331da177e4SLinus Torvalds 	if (LBA_DEV(d)->hw_rev < 3) \
9341da177e4SLinus Torvalds 		lba_t32 = READ_U32(d->base_addr + LBA_FUNC_ID); \
9351da177e4SLinus Torvalds }
9361da177e4SLinus Torvalds 
9371da177e4SLinus Torvalds LBA_PORT_OUT( 8, 3)
9381da177e4SLinus Torvalds LBA_PORT_OUT(16, 2)
9391da177e4SLinus Torvalds LBA_PORT_OUT(32, 0)
9401da177e4SLinus Torvalds 
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds static struct pci_port_ops lba_astro_port_ops = {
9431da177e4SLinus Torvalds 	.inb =	lba_astro_in8,
9441da177e4SLinus Torvalds 	.inw =	lba_astro_in16,
9451da177e4SLinus Torvalds 	.inl =	lba_astro_in32,
9461da177e4SLinus Torvalds 	.outb =	lba_astro_out8,
9471da177e4SLinus Torvalds 	.outw =	lba_astro_out16,
9481da177e4SLinus Torvalds 	.outl =	lba_astro_out32
9491da177e4SLinus Torvalds };
9501da177e4SLinus Torvalds 
9511da177e4SLinus Torvalds 
9521da177e4SLinus Torvalds #ifdef CONFIG_64BIT
9531da177e4SLinus Torvalds #define PIOP_TO_GMMIO(lba, addr) \
9541da177e4SLinus Torvalds 	((lba)->iop_base + (((addr)&0xFFFC)<<10) + ((addr)&3))
9551da177e4SLinus Torvalds 
9561da177e4SLinus Torvalds /*******************************************************
9571da177e4SLinus Torvalds **
9581da177e4SLinus Torvalds ** LBA PAT "I/O Port" Space Accessor Functions
9591da177e4SLinus Torvalds **
9601da177e4SLinus Torvalds ** This set of accessor functions is intended for use with
9611da177e4SLinus Torvalds ** "PAT PDC" firmware (ie Prelude/Rhapsody/Piranha boxes).
9621da177e4SLinus Torvalds **
9631da177e4SLinus Torvalds ** This uses the PIOP space located in the first 64MB of GMMIO.
9641da177e4SLinus Torvalds ** Each rope gets a full 64*KB* (ie 4 bytes per page) this way.
9651da177e4SLinus Torvalds ** bits 1:0 stay the same.  bits 15:2 become 25:12.
9661da177e4SLinus Torvalds ** Then add the base and we can generate an I/O Port cycle.
9671da177e4SLinus Torvalds ********************************************************/
9681da177e4SLinus Torvalds #undef LBA_PORT_IN
9691da177e4SLinus Torvalds #define LBA_PORT_IN(size, mask) \
9701da177e4SLinus Torvalds static u##size lba_pat_in##size (struct pci_hba_data *l, u16 addr) \
9711da177e4SLinus Torvalds { \
9721da177e4SLinus Torvalds 	u##size t; \
973a8043ecbSHarvey Harrison 	DBG_PORT("%s(0x%p, 0x%x) ->", __func__, l, addr); \
9741da177e4SLinus Torvalds 	t = READ_REG##size(PIOP_TO_GMMIO(LBA_DEV(l), addr)); \
9751da177e4SLinus Torvalds 	DBG_PORT(" 0x%x\n", t); \
9761da177e4SLinus Torvalds 	return (t); \
9771da177e4SLinus Torvalds }
9781da177e4SLinus Torvalds 
9791da177e4SLinus Torvalds LBA_PORT_IN( 8, 3)
9801da177e4SLinus Torvalds LBA_PORT_IN(16, 2)
9811da177e4SLinus Torvalds LBA_PORT_IN(32, 0)
9821da177e4SLinus Torvalds 
9831da177e4SLinus Torvalds 
9841da177e4SLinus Torvalds #undef LBA_PORT_OUT
9851da177e4SLinus Torvalds #define LBA_PORT_OUT(size, mask) \
9861da177e4SLinus Torvalds static void lba_pat_out##size (struct pci_hba_data *l, u16 addr, u##size val) \
9871da177e4SLinus Torvalds { \
988c2c4798eSMatthew Wilcox 	void __iomem *where = PIOP_TO_GMMIO(LBA_DEV(l), addr); \
989a8043ecbSHarvey Harrison 	DBG_PORT("%s(0x%p, 0x%x, 0x%x)\n", __func__, l, addr, val); \
9901da177e4SLinus Torvalds 	WRITE_REG##size(val, where); \
9911da177e4SLinus Torvalds 	/* flush the I/O down to the elroy at least */ \
9921da177e4SLinus Torvalds 	lba_t32 = READ_U32(l->base_addr + LBA_FUNC_ID); \
9931da177e4SLinus Torvalds }
9941da177e4SLinus Torvalds 
9951da177e4SLinus Torvalds LBA_PORT_OUT( 8, 3)
9961da177e4SLinus Torvalds LBA_PORT_OUT(16, 2)
9971da177e4SLinus Torvalds LBA_PORT_OUT(32, 0)
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 
10001da177e4SLinus Torvalds static struct pci_port_ops lba_pat_port_ops = {
10011da177e4SLinus Torvalds 	.inb =	lba_pat_in8,
10021da177e4SLinus Torvalds 	.inw =	lba_pat_in16,
10031da177e4SLinus Torvalds 	.inl =	lba_pat_in32,
10041da177e4SLinus Torvalds 	.outb =	lba_pat_out8,
10051da177e4SLinus Torvalds 	.outw =	lba_pat_out16,
10061da177e4SLinus Torvalds 	.outl =	lba_pat_out32
10071da177e4SLinus Torvalds };
10081da177e4SLinus Torvalds 
10091da177e4SLinus Torvalds 
10101da177e4SLinus Torvalds 
10111da177e4SLinus Torvalds /*
10121da177e4SLinus Torvalds ** make range information from PDC available to PCI subsystem.
10131da177e4SLinus Torvalds ** We make the PDC call here in order to get the PCI bus range
10141da177e4SLinus Torvalds ** numbers. The rest will get forwarded in pcibios_fixup_bus().
10151da177e4SLinus Torvalds ** We don't have a struct pci_bus assigned to us yet.
10161da177e4SLinus Torvalds */
10171da177e4SLinus Torvalds static void
lba_pat_resources(struct parisc_device * pa_dev,struct lba_device * lba_dev)10181da177e4SLinus Torvalds lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
10191da177e4SLinus Torvalds {
10201da177e4SLinus Torvalds 	unsigned long bytecnt;
10211d72e83dSHelge Deller 	long io_count __maybe_unused;
10221da177e4SLinus Torvalds 	long status;	/* PDC return status */
10231da177e4SLinus Torvalds 	long pa_count;
1024e957f608SGrant Grundler 	pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;	/* PA_VIEW */
1025e957f608SGrant Grundler 	pdc_pat_cell_mod_maddr_block_t *io_pdc_cell;	/* IO_VIEW */
10261da177e4SLinus Torvalds 	int i;
10271da177e4SLinus Torvalds 
1028e957f608SGrant Grundler 	pa_pdc_cell = kzalloc(sizeof(pdc_pat_cell_mod_maddr_block_t), GFP_KERNEL);
1029e957f608SGrant Grundler 	if (!pa_pdc_cell)
1030e957f608SGrant Grundler 		return;
1031e957f608SGrant Grundler 
1032e957f608SGrant Grundler 	io_pdc_cell = kzalloc(sizeof(pdc_pat_cell_mod_maddr_block_t), GFP_KERNEL);
1033450d6e30SStoyan Gaydarov 	if (!io_pdc_cell) {
1034e957f608SGrant Grundler 		kfree(pa_pdc_cell);
1035e957f608SGrant Grundler 		return;
1036e957f608SGrant Grundler 	}
1037e957f608SGrant Grundler 
10381da177e4SLinus Torvalds 	/* return cell module (IO view) */
10391da177e4SLinus Torvalds 	status = pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
1040e957f608SGrant Grundler 				PA_VIEW, pa_pdc_cell);
1041e957f608SGrant Grundler 	pa_count = pa_pdc_cell->mod[1];
10421da177e4SLinus Torvalds 
10431da177e4SLinus Torvalds 	status |= pdc_pat_cell_module(&bytecnt, pa_dev->pcell_loc, pa_dev->mod_index,
1044e957f608SGrant Grundler 				IO_VIEW, io_pdc_cell);
1045e957f608SGrant Grundler 	io_count = io_pdc_cell->mod[1];
10461da177e4SLinus Torvalds 
10471da177e4SLinus Torvalds 	/* We've already done this once for device discovery...*/
10481da177e4SLinus Torvalds 	if (status != PDC_OK) {
10491da177e4SLinus Torvalds 		panic("pdc_pat_cell_module() call failed for LBA!\n");
10501da177e4SLinus Torvalds 	}
10511da177e4SLinus Torvalds 
1052e957f608SGrant Grundler 	if (PAT_GET_ENTITY(pa_pdc_cell->mod_info) != PAT_ENTITY_LBA) {
10531da177e4SLinus Torvalds 		panic("pdc_pat_cell_module() entity returned != PAT_ENTITY_LBA!\n");
10541da177e4SLinus Torvalds 	}
10551da177e4SLinus Torvalds 
10561da177e4SLinus Torvalds 	/*
10571da177e4SLinus Torvalds 	** Inspect the resources PAT tells us about
10581da177e4SLinus Torvalds 	*/
10591da177e4SLinus Torvalds 	for (i = 0; i < pa_count; i++) {
10601da177e4SLinus Torvalds 		struct {
10611da177e4SLinus Torvalds 			unsigned long type;
10621da177e4SLinus Torvalds 			unsigned long start;
10631da177e4SLinus Torvalds 			unsigned long end;	/* aka finish */
10641da177e4SLinus Torvalds 		} *p, *io;
10651da177e4SLinus Torvalds 		struct resource *r;
10661da177e4SLinus Torvalds 
1067e957f608SGrant Grundler 		p = (void *) &(pa_pdc_cell->mod[2+i*3]);
1068e957f608SGrant Grundler 		io = (void *) &(io_pdc_cell->mod[2+i*3]);
10691da177e4SLinus Torvalds 
10701da177e4SLinus Torvalds 		/* Convert the PAT range data to PCI "struct resource" */
10711da177e4SLinus Torvalds 		switch(p->type & 0xff) {
10721da177e4SLinus Torvalds 		case PAT_PBNUM:
10731da177e4SLinus Torvalds 			lba_dev->hba.bus_num.start = p->start;
10741da177e4SLinus Torvalds 			lba_dev->hba.bus_num.end   = p->end;
107530aa80daSYinghai Lu 			lba_dev->hba.bus_num.flags = IORESOURCE_BUS;
10761da177e4SLinus Torvalds 			break;
10771da177e4SLinus Torvalds 
10781da177e4SLinus Torvalds 		case PAT_LMMIO:
10791da177e4SLinus Torvalds 			/* used to fix up pre-initialized MEM BARs */
1080b204a4d2SHelge Deller 			if (!lba_dev->hba.lmmio_space.flags) {
1081dac76f1bSHelge Deller 				unsigned long lba_len;
1082dac76f1bSHelge Deller 
1083dac76f1bSHelge Deller 				lba_len = ~READ_REG32(lba_dev->hba.base_addr
1084dac76f1bSHelge Deller 						+ LBA_LMMIO_MASK);
1085dac76f1bSHelge Deller 				if ((p->end - p->start) != lba_len)
1086dac76f1bSHelge Deller 					p->end = extend_lmmio_len(p->start,
1087dac76f1bSHelge Deller 						p->end, lba_len);
1088dac76f1bSHelge Deller 
10891da177e4SLinus Torvalds 				sprintf(lba_dev->hba.lmmio_name,
1090645d11d4SMatthew Wilcox 						"PCI%02x LMMIO",
1091645d11d4SMatthew Wilcox 						(int)lba_dev->hba.bus_num.start);
10921da177e4SLinus Torvalds 				lba_dev->hba.lmmio_space_offset = p->start -
10931da177e4SLinus Torvalds 					io->start;
10941da177e4SLinus Torvalds 				r = &lba_dev->hba.lmmio_space;
10951da177e4SLinus Torvalds 				r->name = lba_dev->hba.lmmio_name;
1096b204a4d2SHelge Deller 			} else if (!lba_dev->hba.elmmio_space.flags) {
10971da177e4SLinus Torvalds 				sprintf(lba_dev->hba.elmmio_name,
1098645d11d4SMatthew Wilcox 						"PCI%02x ELMMIO",
1099645d11d4SMatthew Wilcox 						(int)lba_dev->hba.bus_num.start);
11001da177e4SLinus Torvalds 				r = &lba_dev->hba.elmmio_space;
11011da177e4SLinus Torvalds 				r->name = lba_dev->hba.elmmio_name;
11021da177e4SLinus Torvalds 			} else {
11031da177e4SLinus Torvalds 				printk(KERN_WARNING MODULE_NAME
11041da177e4SLinus Torvalds 					" only supports 2 LMMIO resources!\n");
11051da177e4SLinus Torvalds 				break;
11061da177e4SLinus Torvalds 			}
11071da177e4SLinus Torvalds 
11081da177e4SLinus Torvalds 			r->start  = p->start;
11091da177e4SLinus Torvalds 			r->end    = p->end;
11101da177e4SLinus Torvalds 			r->flags  = IORESOURCE_MEM;
11111da177e4SLinus Torvalds 			r->parent = r->sibling = r->child = NULL;
11121da177e4SLinus Torvalds 			break;
11131da177e4SLinus Torvalds 
11141da177e4SLinus Torvalds 		case PAT_GMMIO:
11151da177e4SLinus Torvalds 			/* MMIO space > 4GB phys addr; for 64-bit BAR */
1116645d11d4SMatthew Wilcox 			sprintf(lba_dev->hba.gmmio_name, "PCI%02x GMMIO",
1117645d11d4SMatthew Wilcox 					(int)lba_dev->hba.bus_num.start);
11181da177e4SLinus Torvalds 			r = &lba_dev->hba.gmmio_space;
11191da177e4SLinus Torvalds 			r->name  = lba_dev->hba.gmmio_name;
11201da177e4SLinus Torvalds 			r->start  = p->start;
11211da177e4SLinus Torvalds 			r->end    = p->end;
11221da177e4SLinus Torvalds 			r->flags  = IORESOURCE_MEM;
11231da177e4SLinus Torvalds 			r->parent = r->sibling = r->child = NULL;
11241da177e4SLinus Torvalds 			break;
11251da177e4SLinus Torvalds 
11261da177e4SLinus Torvalds 		case PAT_NPIOP:
11271da177e4SLinus Torvalds 			printk(KERN_WARNING MODULE_NAME
11281da177e4SLinus Torvalds 				" range[%d] : ignoring NPIOP (0x%lx)\n",
11291da177e4SLinus Torvalds 				i, p->start);
11301da177e4SLinus Torvalds 			break;
11311da177e4SLinus Torvalds 
11321da177e4SLinus Torvalds 		case PAT_PIOP:
11331da177e4SLinus Torvalds 			/*
11341da177e4SLinus Torvalds 			** Postable I/O port space is per PCI host adapter.
11351da177e4SLinus Torvalds 			** base of 64MB PIOP region
11361da177e4SLinus Torvalds 			*/
11374bdc0d67SChristoph Hellwig 			lba_dev->iop_base = ioremap(p->start, 64 * 1024 * 1024);
11381da177e4SLinus Torvalds 
1139645d11d4SMatthew Wilcox 			sprintf(lba_dev->hba.io_name, "PCI%02x Ports",
1140645d11d4SMatthew Wilcox 					(int)lba_dev->hba.bus_num.start);
11411da177e4SLinus Torvalds 			r = &lba_dev->hba.io_space;
11421da177e4SLinus Torvalds 			r->name  = lba_dev->hba.io_name;
11431da177e4SLinus Torvalds 			r->start  = HBA_PORT_BASE(lba_dev->hba.hba_num);
11441da177e4SLinus Torvalds 			r->end    = r->start + HBA_PORT_SPACE_SIZE - 1;
11451da177e4SLinus Torvalds 			r->flags  = IORESOURCE_IO;
11461da177e4SLinus Torvalds 			r->parent = r->sibling = r->child = NULL;
11471da177e4SLinus Torvalds 			break;
11481da177e4SLinus Torvalds 
11491da177e4SLinus Torvalds 		default:
11501da177e4SLinus Torvalds 			printk(KERN_WARNING MODULE_NAME
11511da177e4SLinus Torvalds 				" range[%d] : unknown pat range type (0x%lx)\n",
11521da177e4SLinus Torvalds 				i, p->type & 0xff);
11531da177e4SLinus Torvalds 			break;
11541da177e4SLinus Torvalds 		}
11551da177e4SLinus Torvalds 	}
1156e957f608SGrant Grundler 
1157e957f608SGrant Grundler 	kfree(pa_pdc_cell);
1158e957f608SGrant Grundler 	kfree(io_pdc_cell);
11591da177e4SLinus Torvalds }
11601da177e4SLinus Torvalds #else
11611da177e4SLinus Torvalds /* keep compiler from complaining about missing declarations */
11621da177e4SLinus Torvalds #define lba_pat_port_ops lba_astro_port_ops
11631da177e4SLinus Torvalds #define lba_pat_resources(pa_dev, lba_dev)
11641da177e4SLinus Torvalds #endif	/* CONFIG_64BIT */
11651da177e4SLinus Torvalds 
11661da177e4SLinus Torvalds 
11671da177e4SLinus Torvalds static void
lba_legacy_resources(struct parisc_device * pa_dev,struct lba_device * lba_dev)11681da177e4SLinus Torvalds lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
11691da177e4SLinus Torvalds {
11701da177e4SLinus Torvalds 	struct resource *r;
11711da177e4SLinus Torvalds 	int lba_num;
11721da177e4SLinus Torvalds 
11731da177e4SLinus Torvalds 	lba_dev->hba.lmmio_space_offset = PCI_F_EXTEND;
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds 	/*
11761da177e4SLinus Torvalds 	** With "legacy" firmware, the lowest byte of FW_SCRATCH
11771da177e4SLinus Torvalds 	** represents bus->secondary and the second byte represents
11781da177e4SLinus Torvalds 	** bus->subsidiary (i.e. highest PPB programmed by firmware).
11791da177e4SLinus Torvalds 	** PCI bus walk *should* end up with the same result.
11801da177e4SLinus Torvalds 	** FIXME: But we don't have sanity checks in PCI or LBA.
11811da177e4SLinus Torvalds 	*/
11821da177e4SLinus Torvalds 	lba_num = READ_REG32(lba_dev->hba.base_addr + LBA_FW_SCRATCH);
11831da177e4SLinus Torvalds 	r = &(lba_dev->hba.bus_num);
11841da177e4SLinus Torvalds 	r->name = "LBA PCI Busses";
11851da177e4SLinus Torvalds 	r->start = lba_num & 0xff;
11861da177e4SLinus Torvalds 	r->end = (lba_num>>8) & 0xff;
1187b47d4934SBjorn Helgaas 	r->flags = IORESOURCE_BUS;
11881da177e4SLinus Torvalds 
11891da177e4SLinus Torvalds 	/* Set up local PCI Bus resources - we don't need them for
11901da177e4SLinus Torvalds 	** Legacy boxes but it's nice to see in /proc/iomem.
11911da177e4SLinus Torvalds 	*/
11921da177e4SLinus Torvalds 	r = &(lba_dev->hba.lmmio_space);
1193645d11d4SMatthew Wilcox 	sprintf(lba_dev->hba.lmmio_name, "PCI%02x LMMIO",
1194645d11d4SMatthew Wilcox 					(int)lba_dev->hba.bus_num.start);
11951da177e4SLinus Torvalds 	r->name  = lba_dev->hba.lmmio_name;
11961da177e4SLinus Torvalds 
11971da177e4SLinus Torvalds #if 1
11981da177e4SLinus Torvalds 	/* We want the CPU -> IO routing of addresses.
11991da177e4SLinus Torvalds 	 * The SBA BASE/MASK registers control CPU -> IO routing.
12001da177e4SLinus Torvalds 	 * Ask SBA what is routed to this rope/LBA.
12011da177e4SLinus Torvalds 	 */
12021da177e4SLinus Torvalds 	sba_distributed_lmmio(pa_dev, r);
12031da177e4SLinus Torvalds #else
12041da177e4SLinus Torvalds 	/*
12051da177e4SLinus Torvalds 	 * The LBA BASE/MASK registers control IO -> System routing.
12061da177e4SLinus Torvalds 	 *
12071da177e4SLinus Torvalds 	 * The following code works but doesn't get us what we want.
12081da177e4SLinus Torvalds 	 * Well, only because firmware (v5.0) on C3000 doesn't program
12091da177e4SLinus Torvalds 	 * the LBA BASE/MASE registers to be the exact inverse of
12101da177e4SLinus Torvalds 	 * the corresponding SBA registers. Other Astro/Pluto
12111da177e4SLinus Torvalds 	 * based platform firmware may do it right.
12121da177e4SLinus Torvalds 	 *
12131da177e4SLinus Torvalds 	 * Should someone want to mess with MSI, they may need to
12141da177e4SLinus Torvalds 	 * reprogram LBA BASE/MASK registers. Thus preserve the code
12151da177e4SLinus Torvalds 	 * below until MSI is known to work on C3000/A500/N4000/RP3440.
12161da177e4SLinus Torvalds 	 *
12171da177e4SLinus Torvalds 	 * Using the code below, /proc/iomem shows:
12181da177e4SLinus Torvalds 	 * ...
12191da177e4SLinus Torvalds 	 * f0000000-f0ffffff : PCI00 LMMIO
12201da177e4SLinus Torvalds 	 *   f05d0000-f05d0000 : lcd_data
12211da177e4SLinus Torvalds 	 *   f05d0008-f05d0008 : lcd_cmd
12221da177e4SLinus Torvalds 	 * f1000000-f1ffffff : PCI01 LMMIO
12231da177e4SLinus Torvalds 	 * f4000000-f4ffffff : PCI02 LMMIO
12241da177e4SLinus Torvalds 	 *   f4000000-f4001fff : sym53c8xx
12251da177e4SLinus Torvalds 	 *   f4002000-f4003fff : sym53c8xx
12261da177e4SLinus Torvalds 	 *   f4004000-f40043ff : sym53c8xx
12271da177e4SLinus Torvalds 	 *   f4005000-f40053ff : sym53c8xx
12281da177e4SLinus Torvalds 	 *   f4007000-f4007fff : ohci_hcd
12291da177e4SLinus Torvalds 	 *   f4008000-f40083ff : tulip
12301da177e4SLinus Torvalds 	 * f6000000-f6ffffff : PCI03 LMMIO
12311da177e4SLinus Torvalds 	 * f8000000-fbffffff : PCI00 ELMMIO
12321da177e4SLinus Torvalds 	 *   fa100000-fa4fffff : stifb mmio
12331da177e4SLinus Torvalds 	 *   fb000000-fb1fffff : stifb fb
12341da177e4SLinus Torvalds 	 *
12351da177e4SLinus Torvalds 	 * But everything listed under PCI02 actually lives under PCI00.
12361da177e4SLinus Torvalds 	 * This is clearly wrong.
12371da177e4SLinus Torvalds 	 *
12381da177e4SLinus Torvalds 	 * Asking SBA how things are routed tells the correct story:
12391da177e4SLinus Torvalds 	 * LMMIO_BASE/MASK/ROUTE f4000001 fc000000 00000000
12401da177e4SLinus Torvalds 	 * DIR0_BASE/MASK/ROUTE fa000001 fe000000 00000006
12411da177e4SLinus Torvalds 	 * DIR1_BASE/MASK/ROUTE f9000001 ff000000 00000004
12421da177e4SLinus Torvalds 	 * DIR2_BASE/MASK/ROUTE f0000000 fc000000 00000000
12431da177e4SLinus Torvalds 	 * DIR3_BASE/MASK/ROUTE f0000000 fc000000 00000000
12441da177e4SLinus Torvalds 	 *
12451da177e4SLinus Torvalds 	 * Which looks like this in /proc/iomem:
12461da177e4SLinus Torvalds 	 * f4000000-f47fffff : PCI00 LMMIO
12471da177e4SLinus Torvalds 	 *   f4000000-f4001fff : sym53c8xx
12481da177e4SLinus Torvalds 	 *   ...[deteled core devices - same as above]...
12491da177e4SLinus Torvalds 	 *   f4008000-f40083ff : tulip
12501da177e4SLinus Torvalds 	 * f4800000-f4ffffff : PCI01 LMMIO
12511da177e4SLinus Torvalds 	 * f6000000-f67fffff : PCI02 LMMIO
12521da177e4SLinus Torvalds 	 * f7000000-f77fffff : PCI03 LMMIO
12531da177e4SLinus Torvalds 	 * f9000000-f9ffffff : PCI02 ELMMIO
12541da177e4SLinus Torvalds 	 * fa000000-fbffffff : PCI03 ELMMIO
12551da177e4SLinus Torvalds 	 *   fa100000-fa4fffff : stifb mmio
12561da177e4SLinus Torvalds 	 *   fb000000-fb1fffff : stifb fb
12571da177e4SLinus Torvalds 	 *
12581da177e4SLinus Torvalds 	 * ie all Built-in core are under now correctly under PCI00.
12591da177e4SLinus Torvalds 	 * The "PCI02 ELMMIO" directed range is for:
12601da177e4SLinus Torvalds 	 *  +-[02]---03.0  3Dfx Interactive, Inc. Voodoo 2
12611da177e4SLinus Torvalds 	 *
12621da177e4SLinus Torvalds 	 * All is well now.
12631da177e4SLinus Torvalds 	 */
12641da177e4SLinus Torvalds 	r->start = READ_REG32(lba_dev->hba.base_addr + LBA_LMMIO_BASE);
12651da177e4SLinus Torvalds 	if (r->start & 1) {
12661da177e4SLinus Torvalds 		unsigned long rsize;
12671da177e4SLinus Torvalds 
12681da177e4SLinus Torvalds 		r->flags = IORESOURCE_MEM;
12691da177e4SLinus Torvalds 		/* mmio_mask also clears Enable bit */
12701da177e4SLinus Torvalds 		r->start &= mmio_mask;
12713654f012SChristoph Hellwig 		r->start = PCI_HOST_ADDR(&lba_dev->hba, r->start);
12721da177e4SLinus Torvalds 		rsize = ~ READ_REG32(lba_dev->hba.base_addr + LBA_LMMIO_MASK);
12731da177e4SLinus Torvalds 
12741da177e4SLinus Torvalds 		/*
12751da177e4SLinus Torvalds 		** Each rope only gets part of the distributed range.
12761da177e4SLinus Torvalds 		** Adjust "window" for this rope.
12771da177e4SLinus Torvalds 		*/
12781da177e4SLinus Torvalds 		rsize /= ROPES_PER_IOC;
127953f01bbaSMatthew Wilcox 		r->start += (rsize + 1) * LBA_NUM(pa_dev->hpa.start);
12801da177e4SLinus Torvalds 		r->end = r->start + rsize;
12811da177e4SLinus Torvalds 	} else {
12821da177e4SLinus Torvalds 		r->end = r->start = 0;	/* Not enabled. */
12831da177e4SLinus Torvalds 	}
12841da177e4SLinus Torvalds #endif
12851da177e4SLinus Torvalds 
12861da177e4SLinus Torvalds 	/*
12871da177e4SLinus Torvalds 	** "Directed" ranges are used when the "distributed range" isn't
12881da177e4SLinus Torvalds 	** sufficient for all devices below a given LBA.  Typically devices
12891da177e4SLinus Torvalds 	** like graphics cards or X25 may need a directed range when the
12901da177e4SLinus Torvalds 	** bus has multiple slots (ie multiple devices) or the device
12911da177e4SLinus Torvalds 	** needs more than the typical 4 or 8MB a distributed range offers.
12921da177e4SLinus Torvalds 	**
12931da177e4SLinus Torvalds 	** The main reason for ignoring it now frigging complications.
12941da177e4SLinus Torvalds 	** Directed ranges may overlap (and have precedence) over
12951da177e4SLinus Torvalds 	** distributed ranges. Or a distributed range assigned to a unused
12961da177e4SLinus Torvalds 	** rope may be used by a directed range on a different rope.
12971da177e4SLinus Torvalds 	** Support for graphics devices may require fixing this
12981da177e4SLinus Torvalds 	** since they may be assigned a directed range which overlaps
12991da177e4SLinus Torvalds 	** an existing (but unused portion of) distributed range.
13001da177e4SLinus Torvalds 	*/
13011da177e4SLinus Torvalds 	r = &(lba_dev->hba.elmmio_space);
1302645d11d4SMatthew Wilcox 	sprintf(lba_dev->hba.elmmio_name, "PCI%02x ELMMIO",
1303645d11d4SMatthew Wilcox 					(int)lba_dev->hba.bus_num.start);
13041da177e4SLinus Torvalds 	r->name  = lba_dev->hba.elmmio_name;
13051da177e4SLinus Torvalds 
13061da177e4SLinus Torvalds #if 1
13071da177e4SLinus Torvalds 	/* See comment which precedes call to sba_directed_lmmio() */
13081da177e4SLinus Torvalds 	sba_directed_lmmio(pa_dev, r);
13091da177e4SLinus Torvalds #else
13101da177e4SLinus Torvalds 	r->start = READ_REG32(lba_dev->hba.base_addr + LBA_ELMMIO_BASE);
13111da177e4SLinus Torvalds 
13121da177e4SLinus Torvalds 	if (r->start & 1) {
13131da177e4SLinus Torvalds 		unsigned long rsize;
13141da177e4SLinus Torvalds 		r->flags = IORESOURCE_MEM;
13151da177e4SLinus Torvalds 		/* mmio_mask also clears Enable bit */
13161da177e4SLinus Torvalds 		r->start &= mmio_mask;
13173654f012SChristoph Hellwig 		r->start = PCI_HOST_ADDR(&lba_dev->hba, r->start);
13181da177e4SLinus Torvalds 		rsize = READ_REG32(lba_dev->hba.base_addr + LBA_ELMMIO_MASK);
13191da177e4SLinus Torvalds 		r->end = r->start + ~rsize;
13201da177e4SLinus Torvalds 	}
13211da177e4SLinus Torvalds #endif
13221da177e4SLinus Torvalds 
13231da177e4SLinus Torvalds 	r = &(lba_dev->hba.io_space);
1324645d11d4SMatthew Wilcox 	sprintf(lba_dev->hba.io_name, "PCI%02x Ports",
1325645d11d4SMatthew Wilcox 					(int)lba_dev->hba.bus_num.start);
13261da177e4SLinus Torvalds 	r->name  = lba_dev->hba.io_name;
13271da177e4SLinus Torvalds 	r->flags = IORESOURCE_IO;
13281da177e4SLinus Torvalds 	r->start = READ_REG32(lba_dev->hba.base_addr + LBA_IOS_BASE) & ~1L;
13291da177e4SLinus Torvalds 	r->end   = r->start + (READ_REG32(lba_dev->hba.base_addr + LBA_IOS_MASK) ^ (HBA_PORT_SPACE_SIZE - 1));
13301da177e4SLinus Torvalds 
13311da177e4SLinus Torvalds 	/* Virtualize the I/O Port space ranges */
13321da177e4SLinus Torvalds 	lba_num = HBA_PORT_BASE(lba_dev->hba.hba_num);
13331da177e4SLinus Torvalds 	r->start |= lba_num;
13341da177e4SLinus Torvalds 	r->end   |= lba_num;
13351da177e4SLinus Torvalds }
13361da177e4SLinus Torvalds 
13371da177e4SLinus Torvalds 
13381da177e4SLinus Torvalds /**************************************************************************
13391da177e4SLinus Torvalds **
13401da177e4SLinus Torvalds **   LBA initialization code (HW and SW)
13411da177e4SLinus Torvalds **
13421da177e4SLinus Torvalds **   o identify LBA chip itself
13431da177e4SLinus Torvalds **   o initialize LBA chip modes (HardFail)
13441da177e4SLinus Torvalds **   o FIXME: initialize DMA hints for reasonable defaults
13451da177e4SLinus Torvalds **   o enable configuration functions
13461da177e4SLinus Torvalds **   o call pci_register_ops() to discover devs (fixup/fixup_bus get invoked)
13471da177e4SLinus Torvalds **
13481da177e4SLinus Torvalds **************************************************************************/
13491da177e4SLinus Torvalds 
13501da177e4SLinus Torvalds static int __init
lba_hw_init(struct lba_device * d)13511da177e4SLinus Torvalds lba_hw_init(struct lba_device *d)
13521da177e4SLinus Torvalds {
13531da177e4SLinus Torvalds 	u32 stat;
13541da177e4SLinus Torvalds 	u32 bus_reset;	/* PDC_PAT_BUG */
13551da177e4SLinus Torvalds 
13561da177e4SLinus Torvalds #if 0
13571da177e4SLinus Torvalds 	printk(KERN_DEBUG "LBA %lx  STAT_CTL %Lx  ERROR_CFG %Lx  STATUS %Lx DMA_CTL %Lx\n",
13581da177e4SLinus Torvalds 		d->hba.base_addr,
13591da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_STAT_CTL),
13601da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ERROR_CONFIG),
13611da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ERROR_STATUS),
13621da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_DMA_CTL) );
13631da177e4SLinus Torvalds 	printk(KERN_DEBUG "	ARB mask %Lx  pri %Lx  mode %Lx  mtlt %Lx\n",
13641da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ARB_MASK),
13651da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ARB_PRI),
13661da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ARB_MODE),
13671da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_ARB_MTLT) );
13681da177e4SLinus Torvalds 	printk(KERN_DEBUG "	HINT cfg 0x%Lx\n",
13691da177e4SLinus Torvalds 		READ_REG64(d->hba.base_addr + LBA_HINT_CFG));
13701da177e4SLinus Torvalds 	printk(KERN_DEBUG "	HINT reg ");
13711da177e4SLinus Torvalds 	{ int i;
13721da177e4SLinus Torvalds 	for (i=LBA_HINT_BASE; i< (14*8 + LBA_HINT_BASE); i+=8)
13731da177e4SLinus Torvalds 		printk(" %Lx", READ_REG64(d->hba.base_addr + i));
13741da177e4SLinus Torvalds 	}
13751da177e4SLinus Torvalds 	printk("\n");
13761da177e4SLinus Torvalds #endif	/* DEBUG_LBA_PAT */
13771da177e4SLinus Torvalds 
13781da177e4SLinus Torvalds #ifdef CONFIG_64BIT
13791da177e4SLinus Torvalds /*
13801da177e4SLinus Torvalds  * FIXME add support for PDC_PAT_IO "Get slot status" - OLAR support
13811da177e4SLinus Torvalds  * Only N-Class and up can really make use of Get slot status.
13821da177e4SLinus Torvalds  * maybe L-class too but I've never played with it there.
13831da177e4SLinus Torvalds  */
13841da177e4SLinus Torvalds #endif
13851da177e4SLinus Torvalds 
13861da177e4SLinus Torvalds 	/* PDC_PAT_BUG: exhibited in rev 40.48  on L2000 */
13871da177e4SLinus Torvalds 	bus_reset = READ_REG32(d->hba.base_addr + LBA_STAT_CTL + 4) & 1;
13881da177e4SLinus Torvalds 	if (bus_reset) {
13891da177e4SLinus Torvalds 		printk(KERN_DEBUG "NOTICE: PCI bus reset still asserted! (clearing)\n");
13901da177e4SLinus Torvalds 	}
13911da177e4SLinus Torvalds 
13921da177e4SLinus Torvalds 	stat = READ_REG32(d->hba.base_addr + LBA_ERROR_CONFIG);
13931da177e4SLinus Torvalds 	if (stat & LBA_SMART_MODE) {
13941da177e4SLinus Torvalds 		printk(KERN_DEBUG "NOTICE: LBA in SMART mode! (cleared)\n");
13951da177e4SLinus Torvalds 		stat &= ~LBA_SMART_MODE;
13961da177e4SLinus Torvalds 		WRITE_REG32(stat, d->hba.base_addr + LBA_ERROR_CONFIG);
13971da177e4SLinus Torvalds 	}
13981da177e4SLinus Torvalds 
1399b845f66fSHelge Deller 
1400b845f66fSHelge Deller 	/*
1401b845f66fSHelge Deller 	 * Hard Fail vs. Soft Fail on PCI "Master Abort".
1402b845f66fSHelge Deller 	 *
1403b845f66fSHelge Deller 	 * "Master Abort" means the MMIO transaction timed out - usually due to
1404b845f66fSHelge Deller 	 * the device not responding to an MMIO read. We would like HF to be
1405b845f66fSHelge Deller 	 * enabled to find driver problems, though it means the system will
1406b845f66fSHelge Deller 	 * crash with a HPMC.
1407b845f66fSHelge Deller 	 *
1408b845f66fSHelge Deller 	 * In SoftFail mode "~0L" is returned as a result of a timeout on the
1409b845f66fSHelge Deller 	 * pci bus. This is like how PCI busses on x86 and most other
1410b845f66fSHelge Deller 	 * architectures behave.  In order to increase compatibility with
1411b845f66fSHelge Deller 	 * existing (x86) PCI hardware and existing Linux drivers we enable
1412b845f66fSHelge Deller 	 * Soft Faul mode on PA-RISC now too.
1413b845f66fSHelge Deller 	 */
14141da177e4SLinus Torvalds         stat = READ_REG32(d->hba.base_addr + LBA_STAT_CTL);
1415b845f66fSHelge Deller #if defined(ENABLE_HARDFAIL)
14161da177e4SLinus Torvalds 	WRITE_REG32(stat | HF_ENABLE, d->hba.base_addr + LBA_STAT_CTL);
1417b845f66fSHelge Deller #else
1418b845f66fSHelge Deller 	WRITE_REG32(stat & ~HF_ENABLE, d->hba.base_addr + LBA_STAT_CTL);
1419b845f66fSHelge Deller #endif
14201da177e4SLinus Torvalds 
14211da177e4SLinus Torvalds 	/*
14221da177e4SLinus Torvalds 	** Writing a zero to STAT_CTL.rf (bit 0) will clear reset signal
14231da177e4SLinus Torvalds 	** if it's not already set. If we just cleared the PCI Bus Reset
14241da177e4SLinus Torvalds 	** signal, wait a bit for the PCI devices to recover and setup.
14251da177e4SLinus Torvalds 	*/
14261da177e4SLinus Torvalds 	if (bus_reset)
14271da177e4SLinus Torvalds 		mdelay(pci_post_reset_delay);
14281da177e4SLinus Torvalds 
14291da177e4SLinus Torvalds 	if (0 == READ_REG32(d->hba.base_addr + LBA_ARB_MASK)) {
14301da177e4SLinus Torvalds 		/*
14311da177e4SLinus Torvalds 		** PDC_PAT_BUG: PDC rev 40.48 on L2000.
14321da177e4SLinus Torvalds 		** B2000/C3600/J6000 also have this problem?
14331da177e4SLinus Torvalds 		**
14341da177e4SLinus Torvalds 		** Elroys with hot pluggable slots don't get configured
14351da177e4SLinus Torvalds 		** correctly if the slot is empty.  ARB_MASK is set to 0
14361da177e4SLinus Torvalds 		** and we can't master transactions on the bus if it's
14371da177e4SLinus Torvalds 		** not at least one. 0x3 enables elroy and first slot.
14381da177e4SLinus Torvalds 		*/
14391da177e4SLinus Torvalds 		printk(KERN_DEBUG "NOTICE: Enabling PCI Arbitration\n");
14401da177e4SLinus Torvalds 		WRITE_REG32(0x3, d->hba.base_addr + LBA_ARB_MASK);
14411da177e4SLinus Torvalds 	}
14421da177e4SLinus Torvalds 
14431da177e4SLinus Torvalds 	/*
14441da177e4SLinus Torvalds 	** FIXME: Hint registers are programmed with default hint
14451da177e4SLinus Torvalds 	** values by firmware. Hints should be sane even if we
14461da177e4SLinus Torvalds 	** can't reprogram them the way drivers want.
14471da177e4SLinus Torvalds 	*/
14481da177e4SLinus Torvalds 	return 0;
14491da177e4SLinus Torvalds }
14501da177e4SLinus Torvalds 
1451353dfe12SMatthew Wilcox /*
1452353dfe12SMatthew Wilcox  * Unfortunately, when firmware numbers busses, it doesn't take into account
1453353dfe12SMatthew Wilcox  * Cardbus bridges.  So we have to renumber the busses to suit ourselves.
1454353dfe12SMatthew Wilcox  * Elroy/Mercury don't actually know what bus number they're attached to;
1455353dfe12SMatthew Wilcox  * we use bus 0 to indicate the directly attached bus and any other bus
1456353dfe12SMatthew Wilcox  * number will be taken care of by the PCI-PCI bridge.
1457353dfe12SMatthew Wilcox  */
1458353dfe12SMatthew Wilcox static unsigned int lba_next_bus = 0;
14591da177e4SLinus Torvalds 
14601da177e4SLinus Torvalds /*
1461353dfe12SMatthew Wilcox  * Determine if lba should claim this chip (return 0) or not (return 1).
1462353dfe12SMatthew Wilcox  * If so, initialize the chip and tell other partners in crime they
1463353dfe12SMatthew Wilcox  * have work to do.
14641da177e4SLinus Torvalds  */
14651da177e4SLinus Torvalds static int __init
lba_driver_probe(struct parisc_device * dev)14661da177e4SLinus Torvalds lba_driver_probe(struct parisc_device *dev)
14671da177e4SLinus Torvalds {
14681da177e4SLinus Torvalds 	struct lba_device *lba_dev;
1469dc7dce28SBjorn Helgaas 	LIST_HEAD(resources);
14701da177e4SLinus Torvalds 	struct pci_bus *lba_bus;
14711da177e4SLinus Torvalds 	struct pci_ops *cfg_ops;
14721da177e4SLinus Torvalds 	u32 func_class;
14731da177e4SLinus Torvalds 	void *tmp_obj;
14741da177e4SLinus Torvalds 	char *version;
1475cf59f34dSWilliam Dean 	void __iomem *addr;
147630aa80daSYinghai Lu 	int max;
14771da177e4SLinus Torvalds 
1478cf59f34dSWilliam Dean 	addr = ioremap(dev->hpa.start, 4096);
1479cf59f34dSWilliam Dean 	if (addr == NULL)
1480cf59f34dSWilliam Dean 		return -ENOMEM;
1481cf59f34dSWilliam Dean 
14821da177e4SLinus Torvalds 	/* Read HW Rev First */
14831da177e4SLinus Torvalds 	func_class = READ_REG32(addr + LBA_FCLASS);
14841da177e4SLinus Torvalds 
14851da177e4SLinus Torvalds 	if (IS_ELROY(dev)) {
14861da177e4SLinus Torvalds 		func_class &= 0xf;
14871da177e4SLinus Torvalds 		switch (func_class) {
14881da177e4SLinus Torvalds 		case 0:	version = "TR1.0"; break;
14891da177e4SLinus Torvalds 		case 1:	version = "TR2.0"; break;
14901da177e4SLinus Torvalds 		case 2:	version = "TR2.1"; break;
14911da177e4SLinus Torvalds 		case 3:	version = "TR2.2"; break;
14921da177e4SLinus Torvalds 		case 4:	version = "TR3.0"; break;
14931da177e4SLinus Torvalds 		case 5:	version = "TR4.0"; break;
14941da177e4SLinus Torvalds 		default: version = "TR4+";
14951da177e4SLinus Torvalds 		}
14961da177e4SLinus Torvalds 
1497ba9877b6SKyle McMartin 		printk(KERN_INFO "Elroy version %s (0x%x) found at 0x%lx\n",
1498645d11d4SMatthew Wilcox 		       version, func_class & 0xf, (long)dev->hpa.start);
14991da177e4SLinus Torvalds 
15001da177e4SLinus Torvalds 		if (func_class < 2) {
15011da177e4SLinus Torvalds 			printk(KERN_WARNING "Can't support LBA older than "
15021da177e4SLinus Torvalds 				"TR2.1 - continuing under adversity.\n");
15031da177e4SLinus Torvalds 		}
15041da177e4SLinus Torvalds 
15051da177e4SLinus Torvalds #if 0
15061da177e4SLinus Torvalds /* Elroy TR4.0 should work with simple algorithm.
15071da177e4SLinus Torvalds    But it doesn't.  Still missing something. *sigh*
15081da177e4SLinus Torvalds */
15091da177e4SLinus Torvalds 		if (func_class > 4) {
15101da177e4SLinus Torvalds 			cfg_ops = &mercury_cfg_ops;
15111da177e4SLinus Torvalds 		} else
15121da177e4SLinus Torvalds #endif
15131da177e4SLinus Torvalds 		{
15141da177e4SLinus Torvalds 			cfg_ops = &elroy_cfg_ops;
15151da177e4SLinus Torvalds 		}
15161da177e4SLinus Torvalds 
15171da177e4SLinus Torvalds 	} else if (IS_MERCURY(dev) || IS_QUICKSILVER(dev)) {
1518ba9877b6SKyle McMartin 		int major, minor;
1519ba9877b6SKyle McMartin 
15201da177e4SLinus Torvalds 		func_class &= 0xff;
1521ba9877b6SKyle McMartin 		major = func_class >> 4, minor = func_class & 0xf;
1522ba9877b6SKyle McMartin 
15231da177e4SLinus Torvalds 		/* We could use one printk for both Elroy and Mercury,
15241da177e4SLinus Torvalds                  * but for the mask for func_class.
15251da177e4SLinus Torvalds                  */
1526ba9877b6SKyle McMartin 		printk(KERN_INFO "%s version TR%d.%d (0x%x) found at 0x%lx\n",
1527ba9877b6SKyle McMartin 		       IS_MERCURY(dev) ? "Mercury" : "Quicksilver", major,
1528645d11d4SMatthew Wilcox 		       minor, func_class, (long)dev->hpa.start);
1529ba9877b6SKyle McMartin 
15301da177e4SLinus Torvalds 		cfg_ops = &mercury_cfg_ops;
15311da177e4SLinus Torvalds 	} else {
1532645d11d4SMatthew Wilcox 		printk(KERN_ERR "Unknown LBA found at 0x%lx\n",
1533645d11d4SMatthew Wilcox 			(long)dev->hpa.start);
15341da177e4SLinus Torvalds 		return -ENODEV;
15351da177e4SLinus Torvalds 	}
15361da177e4SLinus Torvalds 
1537353dfe12SMatthew Wilcox 	/* Tell I/O SAPIC driver we have a IRQ handler/region. */
15388f01caf0SHelge Deller 	tmp_obj = iosapic_register(dev->hpa.start + LBA_IOSAPIC_BASE,
15398f01caf0SHelge Deller 						addr + LBA_IOSAPIC_BASE);
15401da177e4SLinus Torvalds 
15411da177e4SLinus Torvalds 	/* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't
15421da177e4SLinus Torvalds 	**	have an IRT entry will get NULL back from iosapic code.
15431da177e4SLinus Torvalds 	*/
15441da177e4SLinus Torvalds 
1545cb6fc18eSHelge Deller 	lba_dev = kzalloc(sizeof(struct lba_device), GFP_KERNEL);
15461da177e4SLinus Torvalds 	if (!lba_dev) {
15471da177e4SLinus Torvalds 		printk(KERN_ERR "lba_init_chip - couldn't alloc lba_device\n");
15481da177e4SLinus Torvalds 		return(1);
15491da177e4SLinus Torvalds 	}
15501da177e4SLinus Torvalds 
15511da177e4SLinus Torvalds 
15521da177e4SLinus Torvalds 	/* ---------- First : initialize data we already have --------- */
15531da177e4SLinus Torvalds 
15541da177e4SLinus Torvalds 	lba_dev->hw_rev = func_class;
15551da177e4SLinus Torvalds 	lba_dev->hba.base_addr = addr;
15561da177e4SLinus Torvalds 	lba_dev->hba.dev = dev;
15571da177e4SLinus Torvalds 	lba_dev->iosapic_obj = tmp_obj;  /* save interrupt handle */
15581da177e4SLinus Torvalds 	lba_dev->hba.iommu = sba_get_iommu(dev);  /* get iommu data */
1559b0eecc4dSKyle McMartin 	parisc_set_drvdata(dev, lba_dev);
15601da177e4SLinus Torvalds 
15611da177e4SLinus Torvalds 	/* ------------ Second : initialize common stuff ---------- */
15621da177e4SLinus Torvalds 	pci_bios = &lba_bios_ops;
15633654f012SChristoph Hellwig 	pcibios_register_hba(&lba_dev->hba);
15641da177e4SLinus Torvalds 	spin_lock_init(&lba_dev->lba_lock);
15651da177e4SLinus Torvalds 
15661da177e4SLinus Torvalds 	if (lba_hw_init(lba_dev))
15671da177e4SLinus Torvalds 		return(1);
15681da177e4SLinus Torvalds 
15691da177e4SLinus Torvalds 	/* ---------- Third : setup I/O Port and MMIO resources  --------- */
15701da177e4SLinus Torvalds 
15711da177e4SLinus Torvalds 	if (is_pdc_pat()) {
15721da177e4SLinus Torvalds 		/* PDC PAT firmware uses PIOP region of GMMIO space. */
15731da177e4SLinus Torvalds 		pci_port = &lba_pat_port_ops;
15741da177e4SLinus Torvalds 		/* Go ask PDC PAT what resources this LBA has */
15751da177e4SLinus Torvalds 		lba_pat_resources(dev, lba_dev);
15761da177e4SLinus Torvalds 	} else {
15771da177e4SLinus Torvalds 		if (!astro_iop_base) {
15781da177e4SLinus Torvalds 			/* Sprockets PDC uses NPIOP region */
15794bdc0d67SChristoph Hellwig 			astro_iop_base = ioremap(LBA_PORT_BASE, 64 * 1024);
15801da177e4SLinus Torvalds 			pci_port = &lba_astro_port_ops;
15811da177e4SLinus Torvalds 		}
15821da177e4SLinus Torvalds 
15831da177e4SLinus Torvalds 		/* Poke the chip a bit for /proc output */
15841da177e4SLinus Torvalds 		lba_legacy_resources(dev, lba_dev);
15851da177e4SLinus Torvalds 	}
15861da177e4SLinus Torvalds 
1587353dfe12SMatthew Wilcox 	if (lba_dev->hba.bus_num.start < lba_next_bus)
1588353dfe12SMatthew Wilcox 		lba_dev->hba.bus_num.start = lba_next_bus;
1589353dfe12SMatthew Wilcox 
1590f4d9ea9aSBjorn Helgaas 	/*   Overlaps with elmmio can (and should) fail here.
1591f4d9ea9aSBjorn Helgaas 	 *   We will prune (or ignore) the distributed range.
1592f4d9ea9aSBjorn Helgaas 	 *
1593f4d9ea9aSBjorn Helgaas 	 *   FIXME: SBA code should register all elmmio ranges first.
1594f4d9ea9aSBjorn Helgaas 	 *      that would take care of elmmio ranges routed
1595f4d9ea9aSBjorn Helgaas 	 *	to a different rope (already discovered) from
1596f4d9ea9aSBjorn Helgaas 	 *	getting registered *after* LBA code has already
1597f4d9ea9aSBjorn Helgaas 	 *	registered it's distributed lmmio range.
1598f4d9ea9aSBjorn Helgaas 	 */
1599f4d9ea9aSBjorn Helgaas 	if (truncate_pat_collision(&iomem_resource,
1600f4d9ea9aSBjorn Helgaas 				   &(lba_dev->hba.lmmio_space))) {
1601f4d9ea9aSBjorn Helgaas 		printk(KERN_WARNING "LBA: lmmio_space [%lx/%lx] duplicate!\n",
1602f4d9ea9aSBjorn Helgaas 				(long)lba_dev->hba.lmmio_space.start,
1603f4d9ea9aSBjorn Helgaas 				(long)lba_dev->hba.lmmio_space.end);
1604f4d9ea9aSBjorn Helgaas 		lba_dev->hba.lmmio_space.flags = 0;
1605f4d9ea9aSBjorn Helgaas 	}
1606f4d9ea9aSBjorn Helgaas 
160739c2462eSBjorn Helgaas 	pci_add_resource_offset(&resources, &lba_dev->hba.io_space,
160839c2462eSBjorn Helgaas 				HBA_PORT_BASE(lba_dev->hba.hba_num));
1609b204a4d2SHelge Deller 	if (lba_dev->hba.elmmio_space.flags)
161039c2462eSBjorn Helgaas 		pci_add_resource_offset(&resources, &lba_dev->hba.elmmio_space,
161139c2462eSBjorn Helgaas 					lba_dev->hba.lmmio_space_offset);
1612dc7dce28SBjorn Helgaas 	if (lba_dev->hba.lmmio_space.flags)
161339c2462eSBjorn Helgaas 		pci_add_resource_offset(&resources, &lba_dev->hba.lmmio_space,
161439c2462eSBjorn Helgaas 					lba_dev->hba.lmmio_space_offset);
1615e02a653eSHelge Deller 	if (lba_dev->hba.gmmio_space.flags) {
1616b696e5e9SHelge Deller 		/* Not registering GMMIO space - according to docs it's not
1617b696e5e9SHelge Deller 		 * even used on HP-UX. */
1618e02a653eSHelge Deller 		/* pci_add_resource(&resources, &lba_dev->hba.gmmio_space); */
1619e02a653eSHelge Deller 	}
1620dc7dce28SBjorn Helgaas 
162130aa80daSYinghai Lu 	pci_add_resource(&resources, &lba_dev->hba.bus_num);
162230aa80daSYinghai Lu 
16231da177e4SLinus Torvalds 	dev->dev.platform_data = lba_dev;
16241da177e4SLinus Torvalds 	lba_bus = lba_dev->hba.hba_bus =
1625dc7dce28SBjorn Helgaas 		pci_create_root_bus(&dev->dev, lba_dev->hba.bus_num.start,
1626dc7dce28SBjorn Helgaas 				    cfg_ops, NULL, &resources);
1627dc7dce28SBjorn Helgaas 	if (!lba_bus) {
1628dc7dce28SBjorn Helgaas 		pci_free_resource_list(&resources);
162942605fa6SBjorn Helgaas 		return 0;
1630dc7dce28SBjorn Helgaas 	}
163142605fa6SBjorn Helgaas 
163230aa80daSYinghai Lu 	max = pci_scan_child_bus(lba_bus);
16331da177e4SLinus Torvalds 
16341da177e4SLinus Torvalds 	/* This is in lieu of calling pci_assign_unassigned_resources() */
16351da177e4SLinus Torvalds 	if (is_pdc_pat()) {
16361da177e4SLinus Torvalds 		/* assign resources to un-initialized devices */
16371da177e4SLinus Torvalds 
16381da177e4SLinus Torvalds 		DBG_PAT("LBA pci_bus_size_bridges()\n");
16391da177e4SLinus Torvalds 		pci_bus_size_bridges(lba_bus);
16401da177e4SLinus Torvalds 
16411da177e4SLinus Torvalds 		DBG_PAT("LBA pci_bus_assign_resources()\n");
16421da177e4SLinus Torvalds 		pci_bus_assign_resources(lba_bus);
16431da177e4SLinus Torvalds 
16441da177e4SLinus Torvalds #ifdef DEBUG_LBA_PAT
16451da177e4SLinus Torvalds 		DBG_PAT("\nLBA PIOP resource tree\n");
16461da177e4SLinus Torvalds 		lba_dump_res(&lba_dev->hba.io_space, 2);
16471da177e4SLinus Torvalds 		DBG_PAT("\nLBA LMMIO resource tree\n");
16481da177e4SLinus Torvalds 		lba_dump_res(&lba_dev->hba.lmmio_space, 2);
16491da177e4SLinus Torvalds #endif
16501da177e4SLinus Torvalds 	}
16511da177e4SLinus Torvalds 
16521da177e4SLinus Torvalds 	/*
16531da177e4SLinus Torvalds 	** Once PCI register ops has walked the bus, access to config
16541da177e4SLinus Torvalds 	** space is restricted. Avoids master aborts on config cycles.
16551da177e4SLinus Torvalds 	** Early LBA revs go fatal on *any* master abort.
16561da177e4SLinus Torvalds 	*/
16571da177e4SLinus Torvalds 	if (cfg_ops == &elroy_cfg_ops) {
16581da177e4SLinus Torvalds 		lba_dev->flags |= LBA_FLAG_SKIP_PROBE;
16591da177e4SLinus Torvalds 	}
16601da177e4SLinus Torvalds 
166130aa80daSYinghai Lu 	lba_next_bus = max + 1;
1662fed99b1eSGrant Grundler 	pci_bus_add_devices(lba_bus);
1663fed99b1eSGrant Grundler 
16641da177e4SLinus Torvalds 	/* Whew! Finally done! Tell services we got this one covered. */
16651da177e4SLinus Torvalds 	return 0;
16661da177e4SLinus Torvalds }
16671da177e4SLinus Torvalds 
1668cfe4fbfbSHelge Deller static const struct parisc_device_id lba_tbl[] __initconst = {
16691da177e4SLinus Torvalds 	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, ELROY_HVERS, 0xa },
16701da177e4SLinus Torvalds 	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, MERCURY_HVERS, 0xa },
16711da177e4SLinus Torvalds 	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, QUICKSILVER_HVERS, 0xa },
16721da177e4SLinus Torvalds 	{ 0, }
16731da177e4SLinus Torvalds };
16741da177e4SLinus Torvalds 
1675cfe4fbfbSHelge Deller static struct parisc_driver lba_driver __refdata = {
16761da177e4SLinus Torvalds 	.name =		MODULE_NAME,
16771da177e4SLinus Torvalds 	.id_table =	lba_tbl,
16781da177e4SLinus Torvalds 	.probe =	lba_driver_probe,
16791da177e4SLinus Torvalds };
16801da177e4SLinus Torvalds 
16811da177e4SLinus Torvalds /*
16821da177e4SLinus Torvalds ** One time initialization to let the world know the LBA was found.
16831da177e4SLinus Torvalds ** Must be called exactly once before pci_init().
16841da177e4SLinus Torvalds */
lba_init(void)1685*df3f9359SHelge Deller static int __init lba_init(void)
16861da177e4SLinus Torvalds {
1687*df3f9359SHelge Deller 	return register_parisc_driver(&lba_driver);
16881da177e4SLinus Torvalds }
1689*df3f9359SHelge Deller arch_initcall(lba_init);
16901da177e4SLinus Torvalds 
16911da177e4SLinus Torvalds /*
16921da177e4SLinus Torvalds ** Initialize the IBASE/IMASK registers for LBA (Elroy).
16931da177e4SLinus Torvalds ** Only called from sba_iommu.c in order to route ranges (MMIO vs DMA).
16941da177e4SLinus Torvalds ** sba_iommu is responsible for locking (none needed at init time).
16951da177e4SLinus Torvalds */
lba_set_iregs(struct parisc_device * lba,u32 ibase,u32 imask)16961da177e4SLinus Torvalds void lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask)
16971da177e4SLinus Torvalds {
16984bdc0d67SChristoph Hellwig 	void __iomem * base_addr = ioremap(lba->hpa.start, 4096);
16991da177e4SLinus Torvalds 
17001da177e4SLinus Torvalds 	imask <<= 2;	/* adjust for hints - 2 more bits */
17011da177e4SLinus Torvalds 
17021da177e4SLinus Torvalds 	/* Make sure we aren't trying to set bits that aren't writeable. */
17031da177e4SLinus Torvalds 	WARN_ON((ibase & 0x001fffff) != 0);
17041da177e4SLinus Torvalds 	WARN_ON((imask & 0x001fffff) != 0);
17051da177e4SLinus Torvalds 
1706a8043ecbSHarvey Harrison 	DBG("%s() ibase 0x%x imask 0x%x\n", __func__, ibase, imask);
17071da177e4SLinus Torvalds 	WRITE_REG32( imask, base_addr + LBA_IMASK);
17081da177e4SLinus Torvalds 	WRITE_REG32( ibase, base_addr + LBA_IBASE);
17091da177e4SLinus Torvalds 	iounmap(base_addr);
17101da177e4SLinus Torvalds }
17111da177e4SLinus Torvalds 
1712bcf3f175SHelge Deller 
1713bcf3f175SHelge Deller /*
1714bcf3f175SHelge Deller  * The design of the Diva management card in rp34x0 machines (rp3410, rp3440)
1715bcf3f175SHelge Deller  * seems rushed, so that many built-in components simply don't work.
1716bcf3f175SHelge Deller  * The following quirks disable the serial AUX port and the built-in ATI RV100
1717bcf3f175SHelge Deller  * Radeon 7000 graphics card which both don't have any external connectors and
1718bcf3f175SHelge Deller  * thus are useless, and even worse, e.g. the AUX port occupies ttyS0 and as
1719bcf3f175SHelge Deller  * such makes those machines the only PARISC machines on which we can't use
1720bcf3f175SHelge Deller  * ttyS0 as boot console.
1721bcf3f175SHelge Deller  */
quirk_diva_ati_card(struct pci_dev * dev)1722bcf3f175SHelge Deller static void quirk_diva_ati_card(struct pci_dev *dev)
1723bcf3f175SHelge Deller {
1724bcf3f175SHelge Deller 	if (dev->subsystem_vendor != PCI_VENDOR_ID_HP ||
1725bcf3f175SHelge Deller 	    dev->subsystem_device != 0x1292)
1726bcf3f175SHelge Deller 		return;
1727bcf3f175SHelge Deller 
1728bcf3f175SHelge Deller 	dev_info(&dev->dev, "Hiding Diva built-in ATI card");
1729bcf3f175SHelge Deller 	dev->device = 0;
1730bcf3f175SHelge Deller }
1731bcf3f175SHelge Deller DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QY,
1732bcf3f175SHelge Deller 	quirk_diva_ati_card);
1733bcf3f175SHelge Deller 
quirk_diva_aux_disable(struct pci_dev * dev)1734bcf3f175SHelge Deller static void quirk_diva_aux_disable(struct pci_dev *dev)
1735bcf3f175SHelge Deller {
1736bcf3f175SHelge Deller 	if (dev->subsystem_vendor != PCI_VENDOR_ID_HP ||
1737bcf3f175SHelge Deller 	    dev->subsystem_device != 0x1291)
1738bcf3f175SHelge Deller 		return;
1739bcf3f175SHelge Deller 
1740bcf3f175SHelge Deller 	dev_info(&dev->dev, "Hiding Diva built-in AUX serial device");
1741bcf3f175SHelge Deller 	dev->device = 0;
1742bcf3f175SHelge Deller }
1743bcf3f175SHelge Deller DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA_AUX,
1744bcf3f175SHelge Deller 	quirk_diva_aux_disable);
174581fe5bbaSHelge Deller 
quirk_tosca_aux_disable(struct pci_dev * dev)174681fe5bbaSHelge Deller static void quirk_tosca_aux_disable(struct pci_dev *dev)
174781fe5bbaSHelge Deller {
174881fe5bbaSHelge Deller 	if (dev->subsystem_vendor != PCI_VENDOR_ID_HP ||
174981fe5bbaSHelge Deller 	    dev->subsystem_device != 0x104a)
175081fe5bbaSHelge Deller 		return;
175181fe5bbaSHelge Deller 
175281fe5bbaSHelge Deller 	dev_info(&dev->dev, "Hiding Tosca secondary built-in AUX serial device");
175381fe5bbaSHelge Deller 	dev->device = 0;
175481fe5bbaSHelge Deller }
175581fe5bbaSHelge Deller DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA,
175681fe5bbaSHelge Deller 	quirk_tosca_aux_disable);
1757