]> err.no Git - linux-2.6/blob - include/asm-powerpc/pci-bridge.h
69ea865c01a41647b752ee5756a583d5668e0592
[linux-2.6] / include / asm-powerpc / pci-bridge.h
1 #ifndef _ASM_POWERPC_PCI_BRIDGE_H
2 #define _ASM_POWERPC_PCI_BRIDGE_H
3 #ifdef __KERNEL__
4
5 #ifndef CONFIG_PPC64
6 #include <linux/ioport.h>
7 #include <linux/pci.h>
8
9 struct device_node;
10 struct pci_controller;
11
12 /*
13  * Structure of a PCI controller (host bridge)
14  */
15 struct pci_controller {
16         struct pci_bus *bus;
17         void *arch_data;
18         struct pci_controller *next;
19         struct device *parent;
20
21         int first_busno;
22         int last_busno;
23         int self_busno;
24
25         void __iomem *io_base_virt;
26         resource_size_t io_base_phys;
27
28         /* Some machines (PReP) have a non 1:1 mapping of
29          * the PCI memory space in the CPU bus space
30          */
31         resource_size_t pci_mem_offset;
32
33         struct pci_ops *ops;
34         volatile unsigned int __iomem *cfg_addr;
35         volatile void __iomem *cfg_data;
36
37         /*
38          * Used for variants of PCI indirect handling and possible quirks:
39          *  SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
40          *  EXT_REG - provides access to PCI-e extended registers
41          *  SURPRESS_PRIMARY_BUS - we surpress the setting of PCI_PRIMARY_BUS
42          *   on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
43          *   to determine which bus number to match on when generating type0
44          *   config cycles
45          */
46 #define PPC_INDIRECT_TYPE_SET_CFG_TYPE          (0x00000001)
47 #define PPC_INDIRECT_TYPE_EXT_REG               (0x00000002)
48 #define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS  (0x00000004)
49         u32 indirect_type;
50
51         /* Currently, we limit ourselves to 1 IO range and 3 mem
52          * ranges since the common pci_bus structure can't handle more
53          */
54         struct resource io_resource;
55         struct resource mem_resources[3];
56         int global_number;              /* PCI domain number */
57 };
58
59 static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
60 {
61         return bus->sysdata;
62 }
63
64 /* These are used for config access before all the PCI probing
65    has been done. */
66 int early_read_config_byte(struct pci_controller *hose, int bus, int dev_fn,
67                            int where, u8 *val);
68 int early_read_config_word(struct pci_controller *hose, int bus, int dev_fn,
69                            int where, u16 *val);
70 int early_read_config_dword(struct pci_controller *hose, int bus, int dev_fn,
71                             int where, u32 *val);
72 int early_write_config_byte(struct pci_controller *hose, int bus, int dev_fn,
73                             int where, u8 val);
74 int early_write_config_word(struct pci_controller *hose, int bus, int dev_fn,
75                             int where, u16 val);
76 int early_write_config_dword(struct pci_controller *hose, int bus, int dev_fn,
77                              int where, u32 val);
78
79 extern void setup_indirect_pci_nomap(struct pci_controller* hose,
80                                void __iomem *cfg_addr, void __iomem *cfg_data);
81 extern void setup_indirect_pci(struct pci_controller* hose,
82                                u32 cfg_addr, u32 cfg_data);
83 extern void setup_grackle(struct pci_controller *hose);
84
85 #else
86
87 #include <linux/pci.h>
88 #include <linux/list.h>
89
90 /*
91  * This program is free software; you can redistribute it and/or
92  * modify it under the terms of the GNU General Public License
93  * as published by the Free Software Foundation; either version
94  * 2 of the License, or (at your option) any later version.
95  */
96
97 /*
98  * Structure of a PCI controller (host bridge)
99  */
100 struct pci_controller {
101         struct pci_bus *bus;
102         char is_dynamic;
103         int node;
104         void *arch_data;
105         struct list_head list_node;
106         struct device *parent;
107
108         int first_busno;
109         int last_busno;
110
111         void __iomem *io_base_virt;
112         void *io_base_alloc;
113         resource_size_t io_base_phys;
114
115         /* Some machines have a non 1:1 mapping of
116          * the PCI memory space in the CPU bus space
117          */
118         resource_size_t pci_mem_offset;
119         unsigned long pci_io_size;
120
121         struct pci_ops *ops;
122         volatile unsigned int __iomem *cfg_addr;
123         volatile void __iomem *cfg_data;
124
125         /* Currently, we limit ourselves to 1 IO range and 3 mem
126          * ranges since the common pci_bus structure can't handle more
127          */
128         struct resource io_resource;
129         struct resource mem_resources[3];
130         int global_number;
131         unsigned long buid;
132         unsigned long dma_window_base_cur;
133         unsigned long dma_window_size;
134
135         void *private_data;
136 };
137
138 /*
139  * PCI stuff, for nodes representing PCI devices, pointed to
140  * by device_node->data.
141  */
142 struct pci_controller;
143 struct iommu_table;
144
145 struct pci_dn {
146         int     busno;                  /* pci bus number */
147         int     bussubno;               /* pci subordinate bus number */
148         int     devfn;                  /* pci device and function number */
149         int     class_code;             /* pci device class */
150
151         struct  pci_controller *phb;    /* for pci devices */
152         struct  iommu_table *iommu_table;       /* for phb's or bridges */
153         struct  pci_dev *pcidev;        /* back-pointer to the pci device */
154         struct  device_node *node;      /* back-pointer to the device_node */
155
156         int     pci_ext_config_space;   /* for pci devices */
157
158 #ifdef CONFIG_EEH
159         int     eeh_mode;               /* See eeh.h for possible EEH_MODEs */
160         int     eeh_config_addr;
161         int     eeh_pe_config_addr; /* new-style partition endpoint address */
162         int     eeh_check_count;        /* # times driver ignored error */
163         int     eeh_freeze_count;       /* # times this device froze up. */
164         int     eeh_false_positives;    /* # times this device reported #ff's */
165         u32     config_space[16];       /* saved PCI config space */
166 #endif
167 };
168
169 /* Get the pointer to a device_node's pci_dn */
170 #define PCI_DN(dn)      ((struct pci_dn *) (dn)->data)
171
172 struct device_node *fetch_dev_dn(struct pci_dev *dev);
173
174 /* Get a device_node from a pci_dev.  This code must be fast except
175  * in the case where the sysdata is incorrect and needs to be fixed
176  * up (this will only happen once).
177  * In this case the sysdata will have been inherited from a PCI host
178  * bridge or a PCI-PCI bridge further up the tree, so it will point
179  * to a valid struct pci_dn, just not the one we want.
180  */
181 static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
182 {
183         struct device_node *dn = dev->sysdata;
184         struct pci_dn *pdn = dn->data;
185
186         if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
187                 return dn;      /* fast path.  sysdata is good */
188         return fetch_dev_dn(dev);
189 }
190
191 static inline int pci_device_from_OF_node(struct device_node *np,
192                                           u8 *bus, u8 *devfn)
193 {
194         if (!PCI_DN(np))
195                 return -ENODEV;
196         *bus = PCI_DN(np)->busno;
197         *devfn = PCI_DN(np)->devfn;
198         return 0;
199 }
200
201 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
202 {
203         if (bus->self)
204                 return pci_device_to_OF_node(bus->self);
205         else
206                 return bus->sysdata; /* Must be root bus (PHB) */
207 }
208
209 /** Find the bus corresponding to the indicated device node */
210 struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
211
212 /** Remove all of the PCI devices under this bus */
213 void pcibios_remove_pci_devices(struct pci_bus *bus);
214
215 /** Discover new pci devices under this bus, and add them */
216 void pcibios_add_pci_devices(struct pci_bus * bus);
217 void pcibios_fixup_new_pci_devices(struct pci_bus *bus, int fix_bus);
218
219 extern int pcibios_remove_root_bus(struct pci_controller *phb);
220
221 static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
222 {
223         struct device_node *busdn = bus->sysdata;
224
225         BUG_ON(busdn == NULL);
226         return PCI_DN(busdn)->phb;
227 }
228
229 extern void pcibios_free_controller(struct pci_controller *phb);
230
231 extern void isa_bridge_find_early(struct pci_controller *hose);
232
233 extern int pcibios_unmap_io_space(struct pci_bus *bus);
234 extern int pcibios_map_io_space(struct pci_bus *bus);
235
236 /* Return values for ppc_md.pci_probe_mode function */
237 #define PCI_PROBE_NONE          -1      /* Don't look at this bus at all */
238 #define PCI_PROBE_NORMAL        0       /* Do normal PCI probing */
239 #define PCI_PROBE_DEVTREE       1       /* Instantiate from device tree */
240
241 #ifdef CONFIG_NUMA
242 #define PHB_SET_NODE(PHB, NODE)         ((PHB)->node = (NODE))
243 #else
244 #define PHB_SET_NODE(PHB, NODE)         ((PHB)->node = -1)
245 #endif
246
247 #endif /* CONFIG_PPC64 */
248
249 /* Get the PCI host controller for an OF device */
250 extern struct pci_controller*
251 pci_find_hose_for_OF_device(struct device_node* node);
252
253 /* Fill up host controller resources from the OF node */
254 extern void
255 pci_process_bridge_OF_ranges(struct pci_controller *hose,
256                            struct device_node *dev, int primary);
257
258 /* Allocate a new PCI host bridge structure */
259 extern struct pci_controller *
260 pcibios_alloc_controller(struct device_node *dev);
261 #ifdef CONFIG_PCI
262 extern unsigned long pci_address_to_pio(phys_addr_t address);
263 #else
264 static inline unsigned long pci_address_to_pio(phys_addr_t address)
265 {
266         return (unsigned long)-1;
267 }
268 #endif
269
270
271
272 #endif /* __KERNEL__ */
273 #endif