blob: 4937ce903a888525da194e4d5d535e7af9f9ffea [file] [log] [blame]
David S. Miller9fd8b642007-03-08 21:55:49 -08001/* pci_impl.h: Helper definitions for PCI controller support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Miller9fd8b642007-03-08 21:55:49 -08003 * Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#ifndef PCI_IMPL_H
7#define PCI_IMPL_H
8
9#include <linux/types.h>
10#include <linux/spinlock.h>
David S. Millerc57c2ff2007-05-08 00:43:56 -070011#include <linux/pci.h>
12#include <linux/msi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/io.h>
David S. Millerde8d28b2006-06-22 16:18:54 -070014#include <asm/prom.h>
David S. Millerc57c2ff2007-05-08 00:43:56 -070015#include <asm/iommu.h>
16
17/* The abstraction used here is that there are PCI controllers,
18 * each with one (Sabre) or two (PSYCHO/SCHIZO) PCI bus modules
19 * underneath. Each PCI bus module uses an IOMMU (shared by both
20 * PBMs of a controller, or per-PBM), and if a streaming buffer
21 * is present, each PCI bus module has it's own. (ie. the IOMMU
22 * might be shared between PBMs, the STC is never shared)
23 * Furthermore, each PCI bus module controls it's own autonomous
24 * PCI bus.
25 */
26
27#define PCI_STC_FLUSHFLAG_INIT(STC) \
28 (*((STC)->strbuf_flushflag) = 0UL)
29#define PCI_STC_FLUSHFLAG_SET(STC) \
30 (*((STC)->strbuf_flushflag) != 0UL)
31
David S. Miller759f89e2007-10-11 03:16:13 -070032#ifdef CONFIG_PCI_MSI
33struct pci_pbm_info;
34struct sparc64_msiq_ops {
35 int (*get_head)(struct pci_pbm_info *pbm, unsigned long msiqid,
36 unsigned long *head);
37 int (*dequeue_msi)(struct pci_pbm_info *pbm, unsigned long msiqid,
38 unsigned long *head, unsigned long *msi);
39 int (*set_head)(struct pci_pbm_info *pbm, unsigned long msiqid,
40 unsigned long head);
41 int (*msi_setup)(struct pci_pbm_info *pbm, unsigned long msiqid,
42 unsigned long msi, int is_msi64);
43 int (*msi_teardown)(struct pci_pbm_info *pbm, unsigned long msi);
44 int (*msiq_alloc)(struct pci_pbm_info *pbm);
45 void (*msiq_free)(struct pci_pbm_info *pbm);
46 int (*msiq_build_irq)(struct pci_pbm_info *pbm, unsigned long msiqid,
47 unsigned long devino);
48};
49
50extern void sparc64_pbm_msi_init(struct pci_pbm_info *pbm,
51 const struct sparc64_msiq_ops *ops);
52
53struct sparc64_msiq_cookie {
54 struct pci_pbm_info *pbm;
55 unsigned long msiqid;
56};
57#endif
58
David S. Millerc57c2ff2007-05-08 00:43:56 -070059struct pci_pbm_info {
60 struct pci_pbm_info *next;
David S. Millerd3ae4b52008-09-09 23:54:02 -070061 struct pci_pbm_info *sibling;
David S. Millerc57c2ff2007-05-08 00:43:56 -070062 int index;
63
David S. Millerc57c2ff2007-05-08 00:43:56 -070064 /* Physical address base of controller registers. */
65 unsigned long controller_regs;
66
67 /* Physical address base of PBM registers. */
68 unsigned long pbm_regs;
69
70 /* Physical address of DMA sync register, if any. */
71 unsigned long sync_reg;
72
73 /* Opaque 32-bit system bus Port ID. */
74 u32 portid;
75
76 /* Opaque 32-bit handle used for hypervisor calls. */
77 u32 devhandle;
78
79 /* Chipset version information. */
80 int chip_type;
81#define PBM_CHIP_TYPE_SABRE 1
82#define PBM_CHIP_TYPE_PSYCHO 2
83#define PBM_CHIP_TYPE_SCHIZO 3
84#define PBM_CHIP_TYPE_SCHIZO_PLUS 4
85#define PBM_CHIP_TYPE_TOMATILLO 5
86 int chip_version;
87 int chip_revision;
88
89 /* Name used for top-level resources. */
90 char *name;
91
92 /* OBP specific information. */
93 struct device_node *prom_node;
94 u64 ino_bitmap;
95
96 /* PBM I/O and Memory space resources. */
97 struct resource io_space;
98 struct resource mem_space;
99
100 /* Base of PCI Config space, can be per-PBM or shared. */
101 unsigned long config_space;
102
David S. Millerca3dd882007-05-09 02:35:27 -0700103 /* This will be 12 on PCI-E controllers, 8 elsewhere. */
104 unsigned long config_space_reg_bits;
105
David S. Millerd3ae4b52008-09-09 23:54:02 -0700106 unsigned long pci_afsr;
107 unsigned long pci_afar;
108 unsigned long pci_csr;
109
David S. Millerc57c2ff2007-05-08 00:43:56 -0700110 /* State of 66MHz capabilities on this PBM. */
111 int is_66mhz_capable;
112 int all_devs_66mhz;
113
114#ifdef CONFIG_PCI_MSI
115 /* MSI info. */
116 u32 msiq_num;
117 u32 msiq_ent_count;
118 u32 msiq_first;
119 u32 msiq_first_devino;
David S. Miller759f89e2007-10-11 03:16:13 -0700120 u32 msiq_rotor;
121 struct sparc64_msiq_cookie *msiq_irq_cookies;
David S. Millerc57c2ff2007-05-08 00:43:56 -0700122 u32 msi_num;
123 u32 msi_first;
124 u32 msi_data_mask;
125 u32 msix_data_width;
126 u64 msi32_start;
127 u64 msi64_start;
128 u32 msi32_len;
129 u32 msi64_len;
130 void *msi_queues;
131 unsigned long *msi_bitmap;
David S. Miller759f89e2007-10-11 03:16:13 -0700132 unsigned int *msi_irq_table;
David S. Millerc57c2ff2007-05-08 00:43:56 -0700133 int (*setup_msi_irq)(unsigned int *virt_irq_p, struct pci_dev *pdev,
134 struct msi_desc *entry);
135 void (*teardown_msi_irq)(unsigned int virt_irq, struct pci_dev *pdev);
David S. Miller759f89e2007-10-11 03:16:13 -0700136 const struct sparc64_msiq_ops *msi_ops;
David S. Millerc57c2ff2007-05-08 00:43:56 -0700137#endif /* !(CONFIG_PCI_MSI) */
138
139 /* This PBM's streaming buffer. */
140 struct strbuf stc;
141
142 /* IOMMU state, potentially shared by both PBM segments. */
143 struct iommu *iommu;
144
145 /* Now things for the actual PCI bus probes. */
146 unsigned int pci_first_busno;
147 unsigned int pci_last_busno;
148 struct pci_bus *pci_bus;
David S. Millerc57c2ff2007-05-08 00:43:56 -0700149 struct pci_ops *pci_ops;
David S. Millerc1b1a5f2008-03-19 04:52:48 -0700150
151 int numa_node;
David S. Millerc57c2ff2007-05-08 00:43:56 -0700152};
153
David S. Miller34768bc2007-05-07 23:06:27 -0700154extern struct pci_pbm_info *pci_pbm_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
David S. Miller6c108f12007-05-07 23:49:01 -0700156extern int pci_num_pbms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158/* PCI bus scanning and fixup support. */
David S. Millercfa06522007-05-07 21:51:41 -0700159extern void pci_get_pbm_props(struct pci_pbm_info *pbm);
David S. Miller7cc288a2008-09-01 18:32:13 -0700160extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
161 struct device *parent);
David S. Miller9fd8b642007-03-08 21:55:49 -0800162extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/* Error reporting support. */
David S. Miller6c108f12007-05-07 23:49:01 -0700165extern void pci_scan_for_target_abort(struct pci_pbm_info *, struct pci_bus *);
166extern void pci_scan_for_master_abort(struct pci_pbm_info *, struct pci_bus *);
167extern void pci_scan_for_parity_error(struct pci_pbm_info *, struct pci_bus *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/* Configuration space access. */
170extern void pci_config_read8(u8 *addr, u8 *ret);
171extern void pci_config_read16(u16 *addr, u16 *ret);
172extern void pci_config_read32(u32 *addr, u32 *ret);
173extern void pci_config_write8(u8 *addr, u8 val);
174extern void pci_config_write16(u16 *addr, u16 val);
175extern void pci_config_write32(u32 *addr, u32 val);
176
David S. Millerca3dd882007-05-09 02:35:27 -0700177extern struct pci_ops sun4u_pci_ops;
178extern struct pci_ops sun4v_pci_ops;
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#endif /* !(PCI_IMPL_H) */