xref: /OK3568_Linux_fs/kernel/arch/parisc/include/asm/pci.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __ASM_PARISC_PCI_H
3*4882a593Smuzhiyun #define __ASM_PARISC_PCI_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/scatterlist.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun ** HP PCI platforms generally support multiple bus adapters.
11*4882a593Smuzhiyun **    (workstations 1-~4, servers 2-~32)
12*4882a593Smuzhiyun **
13*4882a593Smuzhiyun ** Newer platforms number the busses across PCI bus adapters *sparsely*.
14*4882a593Smuzhiyun ** E.g. 0, 8, 16, ...
15*4882a593Smuzhiyun **
16*4882a593Smuzhiyun ** Under a PCI bus, most HP platforms support PPBs up to two or three
17*4882a593Smuzhiyun ** levels deep. See "Bit3" product line.
18*4882a593Smuzhiyun */
19*4882a593Smuzhiyun #define PCI_MAX_BUSSES	256
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* To be used as: mdelay(pci_post_reset_delay);
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * post_reset is the time the kernel should stall to prevent anyone from
25*4882a593Smuzhiyun  * accessing the PCI bus once #RESET is de-asserted.
26*4882a593Smuzhiyun  * PCI spec somewhere says 1 second but with multi-PCI bus systems,
27*4882a593Smuzhiyun  * this makes the boot time much longer than necessary.
28*4882a593Smuzhiyun  * 20ms seems to work for all the HP PCI implementations to date.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #define pci_post_reset_delay 50
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun ** pci_hba_data (aka H2P_OBJECT in HP/UX)
35*4882a593Smuzhiyun **
36*4882a593Smuzhiyun ** This is the "common" or "base" data structure which HBA drivers
37*4882a593Smuzhiyun ** (eg Dino or LBA) are required to place at the top of their own
38*4882a593Smuzhiyun ** platform_data structure.  I've heard this called "C inheritance" too.
39*4882a593Smuzhiyun **
40*4882a593Smuzhiyun ** Data needed by pcibios layer belongs here.
41*4882a593Smuzhiyun */
42*4882a593Smuzhiyun struct pci_hba_data {
43*4882a593Smuzhiyun 	void __iomem   *base_addr;	/* aka Host Physical Address */
44*4882a593Smuzhiyun 	const struct parisc_device *dev; /* device from PA bus walk */
45*4882a593Smuzhiyun 	struct pci_bus *hba_bus;	/* primary PCI bus below HBA */
46*4882a593Smuzhiyun 	int		hba_num;	/* I/O port space access "key" */
47*4882a593Smuzhiyun 	struct resource bus_num;	/* PCI bus numbers */
48*4882a593Smuzhiyun 	struct resource io_space;	/* PIOP */
49*4882a593Smuzhiyun 	struct resource lmmio_space;	/* bus addresses < 4Gb */
50*4882a593Smuzhiyun 	struct resource elmmio_space;	/* additional bus addresses < 4Gb */
51*4882a593Smuzhiyun 	struct resource gmmio_space;	/* bus addresses > 4Gb */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	/* NOTE: Dino code assumes it can use *all* of the lmmio_space,
54*4882a593Smuzhiyun 	 * elmmio_space and gmmio_space as a contiguous array of
55*4882a593Smuzhiyun 	 * resources.  This #define represents the array size */
56*4882a593Smuzhiyun 	#define DINO_MAX_LMMIO_RESOURCES	3
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	unsigned long   lmmio_space_offset;  /* CPU view - PCI view */
59*4882a593Smuzhiyun 	struct ioc	*iommu;		/* IOMMU this device is under */
60*4882a593Smuzhiyun 	/* REVISIT - spinlock to protect resources? */
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	#define HBA_NAME_SIZE 16
63*4882a593Smuzhiyun 	char io_name[HBA_NAME_SIZE];
64*4882a593Smuzhiyun 	char lmmio_name[HBA_NAME_SIZE];
65*4882a593Smuzhiyun 	char elmmio_name[HBA_NAME_SIZE];
66*4882a593Smuzhiyun 	char gmmio_name[HBA_NAME_SIZE];
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun ** We support 2^16 I/O ports per HBA.  These are set up in the form
71*4882a593Smuzhiyun ** 0xbbxxxx, where bb is the bus number and xxxx is the I/O port
72*4882a593Smuzhiyun ** space address.
73*4882a593Smuzhiyun */
74*4882a593Smuzhiyun #define HBA_PORT_SPACE_BITS	16
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #define HBA_PORT_BASE(h)	((h) << HBA_PORT_SPACE_BITS)
77*4882a593Smuzhiyun #define HBA_PORT_SPACE_SIZE	(1UL << HBA_PORT_SPACE_BITS)
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #define PCI_PORT_HBA(a)		((a) >> HBA_PORT_SPACE_BITS)
80*4882a593Smuzhiyun #define PCI_PORT_ADDR(a)	((a) & (HBA_PORT_SPACE_SIZE - 1))
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #ifdef CONFIG_64BIT
83*4882a593Smuzhiyun #define PCI_F_EXTEND		0xffffffff00000000UL
84*4882a593Smuzhiyun #else	/* !CONFIG_64BIT */
85*4882a593Smuzhiyun #define PCI_F_EXTEND		0UL
86*4882a593Smuzhiyun #endif /* !CONFIG_64BIT */
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /*
89*4882a593Smuzhiyun ** Most PCI devices (eg Tulip, NCR720) also export the same registers
90*4882a593Smuzhiyun ** to both MMIO and I/O port space.  Due to poor performance of I/O Port
91*4882a593Smuzhiyun ** access under HP PCI bus adapters, strongly recommend the use of MMIO
92*4882a593Smuzhiyun ** address space.
93*4882a593Smuzhiyun **
94*4882a593Smuzhiyun ** While I'm at it more PA programming notes:
95*4882a593Smuzhiyun **
96*4882a593Smuzhiyun ** 1) MMIO stores (writes) are posted operations. This means the processor
97*4882a593Smuzhiyun **    gets an "ACK" before the write actually gets to the device. A read
98*4882a593Smuzhiyun **    to the same device (or typically the bus adapter above it) will
99*4882a593Smuzhiyun **    force in-flight write transaction(s) out to the targeted device
100*4882a593Smuzhiyun **    before the read can complete.
101*4882a593Smuzhiyun **
102*4882a593Smuzhiyun ** 2) The Programmed I/O (PIO) data may not always be strongly ordered with
103*4882a593Smuzhiyun **    respect to DMA on all platforms. Ie PIO data can reach the processor
104*4882a593Smuzhiyun **    before in-flight DMA reaches memory. Since most SMP PA platforms
105*4882a593Smuzhiyun **    are I/O coherent, it generally doesn't matter...but sometimes
106*4882a593Smuzhiyun **    it does.
107*4882a593Smuzhiyun **
108*4882a593Smuzhiyun ** I've helped device driver writers debug both types of problems.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun struct pci_port_ops {
111*4882a593Smuzhiyun 	  u8 (*inb)  (struct pci_hba_data *hba, u16 port);
112*4882a593Smuzhiyun 	 u16 (*inw)  (struct pci_hba_data *hba, u16 port);
113*4882a593Smuzhiyun 	 u32 (*inl)  (struct pci_hba_data *hba, u16 port);
114*4882a593Smuzhiyun 	void (*outb) (struct pci_hba_data *hba, u16 port,  u8 data);
115*4882a593Smuzhiyun 	void (*outw) (struct pci_hba_data *hba, u16 port, u16 data);
116*4882a593Smuzhiyun 	void (*outl) (struct pci_hba_data *hba, u16 port, u32 data);
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun struct pci_bios_ops {
121*4882a593Smuzhiyun 	void (*init)(void);
122*4882a593Smuzhiyun 	void (*fixup_bus)(struct pci_bus *bus);
123*4882a593Smuzhiyun };
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun ** Stuff declared in arch/parisc/kernel/pci.c
127*4882a593Smuzhiyun */
128*4882a593Smuzhiyun extern struct pci_port_ops *pci_port;
129*4882a593Smuzhiyun extern struct pci_bios_ops *pci_bios;
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun #ifdef CONFIG_PCI
132*4882a593Smuzhiyun extern void pcibios_register_hba(struct pci_hba_data *);
133*4882a593Smuzhiyun #else
pcibios_register_hba(struct pci_hba_data * x)134*4882a593Smuzhiyun static inline void pcibios_register_hba(struct pci_hba_data *x)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun #endif
138*4882a593Smuzhiyun extern void pcibios_init_bridge(struct pci_dev *);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun /*
141*4882a593Smuzhiyun  * pcibios_assign_all_busses() is used in drivers/pci/pci.c:pci_do_scan_bus()
142*4882a593Smuzhiyun  *   0 == check if bridge is numbered before re-numbering.
143*4882a593Smuzhiyun  *   1 == pci_do_scan_bus() should automatically number all PCI-PCI bridges.
144*4882a593Smuzhiyun  *
145*4882a593Smuzhiyun  *   We *should* set this to zero for "legacy" platforms and one
146*4882a593Smuzhiyun  *   for PAT platforms.
147*4882a593Smuzhiyun  *
148*4882a593Smuzhiyun  *   But legacy platforms also need to renumber the busses below a Host
149*4882a593Smuzhiyun  *   Bus controller.  Adding a 4-port Tulip card on the first PCI root
150*4882a593Smuzhiyun  *   bus of a C200 resulted in the secondary bus being numbered as 1.
151*4882a593Smuzhiyun  *   The second PCI host bus controller's root bus had already been
152*4882a593Smuzhiyun  *   assigned bus number 1 by firmware and sysfs complained.
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  *   Firmware isn't doing anything wrong here since each controller
155*4882a593Smuzhiyun  *   is its own PCI domain.  It's simpler and easier for us to renumber
156*4882a593Smuzhiyun  *   the busses rather than treat each Dino as a separate PCI domain.
157*4882a593Smuzhiyun  *   Eventually, we may want to introduce PCI domains for Superdome or
158*4882a593Smuzhiyun  *   rp7420/8420 boxes and then revisit this issue.
159*4882a593Smuzhiyun  */
160*4882a593Smuzhiyun #define pcibios_assign_all_busses()     (1)
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun #define PCIBIOS_MIN_IO          0x10
163*4882a593Smuzhiyun #define PCIBIOS_MIN_MEM         0x1000 /* NBPG - but pci/setup-res.c dies */
164*4882a593Smuzhiyun 
pci_get_legacy_ide_irq(struct pci_dev * dev,int channel)165*4882a593Smuzhiyun static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun 	return channel ? 15 : 14;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun #define HAVE_PCI_MMAP
171*4882a593Smuzhiyun #define ARCH_GENERIC_PCI_MMAP_RESOURCE
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun #endif /* __ASM_PARISC_PCI_H */
174