xref: /linux/arch/x86/include/asm/pci_x86.h (revision 21461775f3d173dedec27a0402d426ba422d80a1)
182487711SJaswinder Singh Rajput /*
282487711SJaswinder Singh Rajput  *	Low-Level PCI Access for i386 machines.
382487711SJaswinder Singh Rajput  *
482487711SJaswinder Singh Rajput  *	(c) 1999 Martin Mares <mj@ucw.cz>
582487711SJaswinder Singh Rajput  */
682487711SJaswinder Singh Rajput 
782487711SJaswinder Singh Rajput #undef DEBUG
882487711SJaswinder Singh Rajput 
982487711SJaswinder Singh Rajput #ifdef DEBUG
10c767a54bSJoe Perches #define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
1182487711SJaswinder Singh Rajput #else
12c767a54bSJoe Perches #define DBG(fmt, ...)				\
13c767a54bSJoe Perches do {						\
14c767a54bSJoe Perches 	if (0)					\
15c767a54bSJoe Perches 		printk(fmt, ##__VA_ARGS__);	\
16c767a54bSJoe Perches } while (0)
1782487711SJaswinder Singh Rajput #endif
1882487711SJaswinder Singh Rajput 
1982487711SJaswinder Singh Rajput #define PCI_PROBE_BIOS		0x0001
2082487711SJaswinder Singh Rajput #define PCI_PROBE_CONF1		0x0002
2182487711SJaswinder Singh Rajput #define PCI_PROBE_CONF2		0x0004
2282487711SJaswinder Singh Rajput #define PCI_PROBE_MMCONF	0x0008
2382487711SJaswinder Singh Rajput #define PCI_PROBE_MASK		0x000f
2482487711SJaswinder Singh Rajput #define PCI_PROBE_NOEARLY	0x0010
2582487711SJaswinder Singh Rajput 
2682487711SJaswinder Singh Rajput #define PCI_NO_CHECKS		0x0400
2782487711SJaswinder Singh Rajput #define PCI_USE_PIRQ_MASK	0x0800
2882487711SJaswinder Singh Rajput #define PCI_ASSIGN_ROMS		0x1000
2982487711SJaswinder Singh Rajput #define PCI_BIOS_IRQ_SCAN	0x2000
3082487711SJaswinder Singh Rajput #define PCI_ASSIGN_ALL_BUSSES	0x4000
3182487711SJaswinder Singh Rajput #define PCI_CAN_SKIP_ISA_ALIGN	0x8000
32236e946bSLinus Torvalds #define PCI_USE__CRS		0x10000
3382487711SJaswinder Singh Rajput #define PCI_CHECK_ENABLE_AMD_MMCONF	0x20000
3482487711SJaswinder Singh Rajput #define PCI_HAS_IO_ECS		0x40000
3582487711SJaswinder Singh Rajput #define PCI_NOASSIGN_ROMS	0x80000
367bc5e3f2SBjorn Helgaas #define PCI_ROOT_NO_CRS		0x100000
377bd1c365SMike Habeck #define PCI_NOASSIGN_BARS	0x200000
3882487711SJaswinder Singh Rajput 
3982487711SJaswinder Singh Rajput extern unsigned int pci_probe;
4082487711SJaswinder Singh Rajput extern unsigned long pirq_table_addr;
4182487711SJaswinder Singh Rajput 
4282487711SJaswinder Singh Rajput enum pci_bf_sort_state {
4382487711SJaswinder Singh Rajput 	pci_bf_sort_default,
4482487711SJaswinder Singh Rajput 	pci_force_nobf,
4582487711SJaswinder Singh Rajput 	pci_force_bf,
4682487711SJaswinder Singh Rajput 	pci_dmi_bf,
4782487711SJaswinder Singh Rajput };
4882487711SJaswinder Singh Rajput 
4982487711SJaswinder Singh Rajput /* pci-i386.c */
5082487711SJaswinder Singh Rajput 
5182487711SJaswinder Singh Rajput void pcibios_resource_survey(void);
5244de3395SAlex Nixon void pcibios_set_cache_line_size(void);
5382487711SJaswinder Singh Rajput 
5482487711SJaswinder Singh Rajput /* pci-pc.c */
5582487711SJaswinder Singh Rajput 
5682487711SJaswinder Singh Rajput extern int pcibios_last_bus;
5782487711SJaswinder Singh Rajput extern struct pci_ops pci_root_ops;
5882487711SJaswinder Singh Rajput 
595707b24aSAristeu Rozanski void pcibios_scan_specific_bus(int busn);
605707b24aSAristeu Rozanski 
6182487711SJaswinder Singh Rajput /* pci-irq.c */
6282487711SJaswinder Singh Rajput 
6382487711SJaswinder Singh Rajput struct irq_info {
6482487711SJaswinder Singh Rajput 	u8 bus, devfn;			/* Bus, device and function */
6582487711SJaswinder Singh Rajput 	struct {
6682487711SJaswinder Singh Rajput 		u8 link;		/* IRQ line ID, chipset dependent,
6782487711SJaswinder Singh Rajput 					   0 = not routed */
6882487711SJaswinder Singh Rajput 		u16 bitmap;		/* Available IRQs */
6982487711SJaswinder Singh Rajput 	} __attribute__((packed)) irq[4];
7082487711SJaswinder Singh Rajput 	u8 slot;			/* Slot number, 0=onboard */
7182487711SJaswinder Singh Rajput 	u8 rfu;
7282487711SJaswinder Singh Rajput } __attribute__((packed));
7382487711SJaswinder Singh Rajput 
7482487711SJaswinder Singh Rajput struct irq_routing_table {
7582487711SJaswinder Singh Rajput 	u32 signature;			/* PIRQ_SIGNATURE should be here */
7682487711SJaswinder Singh Rajput 	u16 version;			/* PIRQ_VERSION */
7782487711SJaswinder Singh Rajput 	u16 size;			/* Table size in bytes */
7882487711SJaswinder Singh Rajput 	u8 rtr_bus, rtr_devfn;		/* Where the interrupt router lies */
7982487711SJaswinder Singh Rajput 	u16 exclusive_irqs;		/* IRQs devoted exclusively to
8082487711SJaswinder Singh Rajput 					   PCI usage */
8182487711SJaswinder Singh Rajput 	u16 rtr_vendor, rtr_device;	/* Vendor and device ID of
8282487711SJaswinder Singh Rajput 					   interrupt router */
8382487711SJaswinder Singh Rajput 	u32 miniport_data;		/* Crap */
8482487711SJaswinder Singh Rajput 	u8 rfu[11];
8582487711SJaswinder Singh Rajput 	u8 checksum;			/* Modulo 256 checksum must give 0 */
8682487711SJaswinder Singh Rajput 	struct irq_info slots[0];
8782487711SJaswinder Singh Rajput } __attribute__((packed));
8882487711SJaswinder Singh Rajput 
8982487711SJaswinder Singh Rajput extern unsigned int pcibios_irq_mask;
9082487711SJaswinder Singh Rajput 
91d19f61f0SThomas Gleixner extern raw_spinlock_t pci_config_lock;
9282487711SJaswinder Singh Rajput 
9382487711SJaswinder Singh Rajput extern int (*pcibios_enable_irq)(struct pci_dev *dev);
9482487711SJaswinder Singh Rajput extern void (*pcibios_disable_irq)(struct pci_dev *dev);
9582487711SJaswinder Singh Rajput 
9682487711SJaswinder Singh Rajput struct pci_raw_ops {
9782487711SJaswinder Singh Rajput 	int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
9882487711SJaswinder Singh Rajput 						int reg, int len, u32 *val);
9982487711SJaswinder Singh Rajput 	int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10082487711SJaswinder Singh Rajput 						int reg, int len, u32 val);
10182487711SJaswinder Singh Rajput };
10282487711SJaswinder Singh Rajput 
10372da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ops;
10472da0b07SJan Beulich extern const struct pci_raw_ops *raw_pci_ext_ops;
10582487711SJaswinder Singh Rajput 
106c0fa4078SJiang Liu extern const struct pci_raw_ops pci_mmcfg;
10772da0b07SJan Beulich extern const struct pci_raw_ops pci_direct_conf1;
10882487711SJaswinder Singh Rajput extern bool port_cf9_safe;
10982487711SJaswinder Singh Rajput 
11082487711SJaswinder Singh Rajput /* arch_initcall level */
11182487711SJaswinder Singh Rajput extern int pci_direct_probe(void);
11282487711SJaswinder Singh Rajput extern void pci_direct_init(int type);
11382487711SJaswinder Singh Rajput extern void pci_pcbios_init(void);
11482487711SJaswinder Singh Rajput extern void __init dmi_check_pciprobe(void);
11582487711SJaswinder Singh Rajput extern void __init dmi_check_skip_isa_align(void);
11682487711SJaswinder Singh Rajput 
11782487711SJaswinder Singh Rajput /* some common used subsys_initcalls */
11882487711SJaswinder Singh Rajput extern int __init pci_acpi_init(void);
119ab3b3793SThomas Gleixner extern void __init pcibios_irq_init(void);
12082487711SJaswinder Singh Rajput extern int __init pcibios_init(void);
121b72d0db9SThomas Gleixner extern int pci_legacy_init(void);
1229325a28cSThomas Gleixner extern void pcibios_fixup_irqs(void);
12382487711SJaswinder Singh Rajput 
12482487711SJaswinder Singh Rajput /* pci-mmconfig.c */
12582487711SJaswinder Singh Rajput 
12656ddf4d3SBjorn Helgaas /* "PCI MMCONFIG %04x [bus %02x-%02x]" */
12756ddf4d3SBjorn Helgaas #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2)
12856ddf4d3SBjorn Helgaas 
129d215a9c8SBjorn Helgaas struct pci_mmcfg_region {
130ff097dddSBjorn Helgaas 	struct list_head list;
13156ddf4d3SBjorn Helgaas 	struct resource res;
132d215a9c8SBjorn Helgaas 	u64 address;
1333f0f5503SBjorn Helgaas 	char __iomem *virt;
134d7e6b66fSBjorn Helgaas 	u16 segment;
135d7e6b66fSBjorn Helgaas 	u8 start_bus;
136d7e6b66fSBjorn Helgaas 	u8 end_bus;
13756ddf4d3SBjorn Helgaas 	char name[PCI_MMCFG_RESOURCE_NAME_LEN];
138d215a9c8SBjorn Helgaas };
139d215a9c8SBjorn Helgaas 
14082487711SJaswinder Singh Rajput extern int __init pci_mmcfg_arch_init(void);
14182487711SJaswinder Singh Rajput extern void __init pci_mmcfg_arch_free(void);
142a18e3690SGreg Kroah-Hartman extern int pci_mmcfg_arch_map(struct pci_mmcfg_region *cfg);
1439cf0105dSJiang Liu extern void pci_mmcfg_arch_unmap(struct pci_mmcfg_region *cfg);
144a18e3690SGreg Kroah-Hartman extern int pci_mmconfig_insert(struct device *dev, u16 seg, u8 start, u8 end,
145a18e3690SGreg Kroah-Hartman 			       phys_addr_t addr);
1469c95111bSJiang Liu extern int pci_mmconfig_delete(u16 seg, u8 start, u8 end);
147f6e1d8ccSBjorn Helgaas extern struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus);
14882487711SJaswinder Singh Rajput 
149ff097dddSBjorn Helgaas extern struct list_head pci_mmcfg_list;
150c4bf2f37SLen Brown 
151df5eb1d6SBjorn Helgaas #define PCI_MMCFG_BUS_OFFSET(bus)      ((bus) << 20)
152df5eb1d6SBjorn Helgaas 
15382487711SJaswinder Singh Rajput /*
154*21461775STomasz Nowicki  * On AMD Fam10h CPUs, all PCI MMIO configuration space accesses must use
155*21461775STomasz Nowicki  * %eax.  No other source or target registers may be used.  The following
156*21461775STomasz Nowicki  * mmio_config_* accessors enforce this.  See "BIOS and Kernel Developer's
157*21461775STomasz Nowicki  * Guide (BKDG) For AMD Family 10h Processors", rev. 3.48, sec 2.11.1,
158*21461775STomasz Nowicki  * "MMIO Configuration Coding Requirements".
15982487711SJaswinder Singh Rajput  */
16082487711SJaswinder Singh Rajput static inline unsigned char mmio_config_readb(void __iomem *pos)
16182487711SJaswinder Singh Rajput {
16282487711SJaswinder Singh Rajput 	u8 val;
16382487711SJaswinder Singh Rajput 	asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos));
16482487711SJaswinder Singh Rajput 	return val;
16582487711SJaswinder Singh Rajput }
16682487711SJaswinder Singh Rajput 
16782487711SJaswinder Singh Rajput static inline unsigned short mmio_config_readw(void __iomem *pos)
16882487711SJaswinder Singh Rajput {
16982487711SJaswinder Singh Rajput 	u16 val;
17082487711SJaswinder Singh Rajput 	asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos));
17182487711SJaswinder Singh Rajput 	return val;
17282487711SJaswinder Singh Rajput }
17382487711SJaswinder Singh Rajput 
17482487711SJaswinder Singh Rajput static inline unsigned int mmio_config_readl(void __iomem *pos)
17582487711SJaswinder Singh Rajput {
17682487711SJaswinder Singh Rajput 	u32 val;
17782487711SJaswinder Singh Rajput 	asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos));
17882487711SJaswinder Singh Rajput 	return val;
17982487711SJaswinder Singh Rajput }
18082487711SJaswinder Singh Rajput 
18182487711SJaswinder Singh Rajput static inline void mmio_config_writeb(void __iomem *pos, u8 val)
18282487711SJaswinder Singh Rajput {
18382487711SJaswinder Singh Rajput 	asm volatile("movb %%al,(%1)" : : "a" (val), "r" (pos) : "memory");
18482487711SJaswinder Singh Rajput }
18582487711SJaswinder Singh Rajput 
18682487711SJaswinder Singh Rajput static inline void mmio_config_writew(void __iomem *pos, u16 val)
18782487711SJaswinder Singh Rajput {
18882487711SJaswinder Singh Rajput 	asm volatile("movw %%ax,(%1)" : : "a" (val), "r" (pos) : "memory");
18982487711SJaswinder Singh Rajput }
19082487711SJaswinder Singh Rajput 
19182487711SJaswinder Singh Rajput static inline void mmio_config_writel(void __iomem *pos, u32 val)
19282487711SJaswinder Singh Rajput {
19382487711SJaswinder Singh Rajput 	asm volatile("movl %%eax,(%1)" : : "a" (val), "r" (pos) : "memory");
19482487711SJaswinder Singh Rajput }
195b72d0db9SThomas Gleixner 
196b72d0db9SThomas Gleixner #ifdef CONFIG_PCI
197b72d0db9SThomas Gleixner # ifdef CONFIG_ACPI
198b72d0db9SThomas Gleixner #  define x86_default_pci_init		pci_acpi_init
199b72d0db9SThomas Gleixner # else
200b72d0db9SThomas Gleixner #  define x86_default_pci_init		pci_legacy_init
201b72d0db9SThomas Gleixner # endif
202ab3b3793SThomas Gleixner # define x86_default_pci_init_irq	pcibios_irq_init
2039325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs	pcibios_fixup_irqs
204b72d0db9SThomas Gleixner #else
205b72d0db9SThomas Gleixner # define x86_default_pci_init		NULL
206ab3b3793SThomas Gleixner # define x86_default_pci_init_irq	NULL
2079325a28cSThomas Gleixner # define x86_default_pci_fixup_irqs	NULL
208b72d0db9SThomas Gleixner #endif
209