[PATCH] powerpc: Update OF address parsers
[powerpc.git] / include / asm-powerpc / pci-bridge.h
1 #ifndef _ASM_POWERPC_PCI_BRIDGE_H
2 #define _ASM_POWERPC_PCI_BRIDGE_H
3
4 #ifndef CONFIG_PPC64
5 #include <asm-ppc/pci-bridge.h>
6 #else
7
8 #include <linux/pci.h>
9 #include <linux/list.h>
10
11 /*
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version
15  * 2 of the License, or (at your option) any later version.
16  */
17
18 /*
19  * Structure of a PCI controller (host bridge)
20  */
21 struct pci_controller {
22         struct pci_bus *bus;
23         char is_dynamic;
24         void *arch_data;
25         struct list_head list_node;
26
27         int first_busno;
28         int last_busno;
29
30         void __iomem *io_base_virt;
31         unsigned long io_base_phys;
32
33         /* Some machines have a non 1:1 mapping of
34          * the PCI memory space in the CPU bus space
35          */
36         unsigned long pci_mem_offset;
37         unsigned long pci_io_size;
38
39         struct pci_ops *ops;
40         volatile unsigned int __iomem *cfg_addr;
41         volatile void __iomem *cfg_data;
42
43         /* Currently, we limit ourselves to 1 IO range and 3 mem
44          * ranges since the common pci_bus structure can't handle more
45          */
46         struct resource io_resource;
47         struct resource mem_resources[3];
48         int global_number;              
49         int local_number;               
50         unsigned long buid;
51         unsigned long dma_window_base_cur;
52         unsigned long dma_window_size;
53 };
54
55 /*
56  * PCI stuff, for nodes representing PCI devices, pointed to
57  * by device_node->data.
58  */
59 struct pci_controller;
60 struct iommu_table;
61
62 struct pci_dn {
63         int     busno;                  /* for pci devices */
64         int     bussubno;               /* for pci devices */
65         int     devfn;                  /* for pci devices */
66
67 #ifdef CONFIG_PPC_PSERIES
68         int     eeh_mode;               /* See eeh.h for possible EEH_MODEs */
69         int     eeh_config_addr;
70         int     eeh_check_count;        /* # times driver ignored error */
71         int     eeh_freeze_count;       /* # times this device froze up. */
72         int     eeh_is_bridge;          /* device is pci-to-pci bridge */
73 #endif
74         int     pci_ext_config_space;   /* for pci devices */
75         struct  pci_controller *phb;    /* for pci devices */
76         struct  iommu_table *iommu_table;       /* for phb's or bridges */
77         struct  pci_dev *pcidev;        /* back-pointer to the pci device */
78         struct  device_node *node;      /* back-pointer to the device_node */
79 #ifdef CONFIG_PPC_ISERIES
80         struct  list_head Device_List;
81         int     Irq;                    /* Assigned IRQ */
82         int     Flags;                  /* Possible flags(disable/bist)*/
83         u8      LogicalSlot;            /* Hv Slot Index for Tces */
84 #endif
85         u32     config_space[16];       /* saved PCI config space */
86 };
87
88 /* Get the pointer to a device_node's pci_dn */
89 #define PCI_DN(dn)      ((struct pci_dn *) (dn)->data)
90
91 struct device_node *fetch_dev_dn(struct pci_dev *dev);
92
93 /* Get a device_node from a pci_dev.  This code must be fast except
94  * in the case where the sysdata is incorrect and needs to be fixed
95  * up (this will only happen once).
96  * In this case the sysdata will have been inherited from a PCI host
97  * bridge or a PCI-PCI bridge further up the tree, so it will point
98  * to a valid struct pci_dn, just not the one we want.
99  */
100 static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
101 {
102         struct device_node *dn = dev->sysdata;
103         struct pci_dn *pdn = dn->data;
104
105         if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
106                 return dn;      /* fast path.  sysdata is good */
107         return fetch_dev_dn(dev);
108 }
109
110 static inline int pci_device_from_OF_node(struct device_node *np,
111                                           u8 *bus, u8 *devfn)
112 {
113         if (!PCI_DN(np))
114                 return -ENODEV;
115         *bus = PCI_DN(np)->busno;
116         *devfn = PCI_DN(np)->devfn;
117         return 0;
118 }
119
120 static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
121 {
122         if (bus->self)
123                 return pci_device_to_OF_node(bus->self);
124         else
125                 return bus->sysdata; /* Must be root bus (PHB) */
126 }
127
128 /** Find the bus corresponding to the indicated device node */
129 struct pci_bus * pcibios_find_pci_bus(struct device_node *dn);
130
131 extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
132                                          struct device_node *dev, int primary);
133
134 /** Remove all of the PCI devices under this bus */
135 void pcibios_remove_pci_devices(struct pci_bus *bus);
136
137 /** Discover new pci devices under this bus, and add them */
138 void pcibios_add_pci_devices(struct pci_bus * bus);
139
140 extern int pcibios_remove_root_bus(struct pci_controller *phb);
141
142 extern void phbs_remap_io(void);
143
144 static inline struct pci_controller *pci_bus_to_host(struct pci_bus *bus)
145 {
146         struct device_node *busdn = bus->sysdata;
147
148         BUG_ON(busdn == NULL);
149         return PCI_DN(busdn)->phb;
150 }
151
152 extern struct pci_controller*
153 pci_find_hose_for_OF_device(struct device_node* node);
154
155 extern struct pci_controller *
156 pcibios_alloc_controller(struct device_node *dev);
157 extern void pcibios_free_controller(struct pci_controller *phb);
158
159 #ifdef CONFIG_PCI
160 extern unsigned int pci_address_to_pio(phys_addr_t address);
161 #else
162 static inline unsigned int pci_address_to_pio(phys_addr_t address)
163 {
164         return (unsigned int)-1;
165 }
166 #endif
167
168 /* Return values for ppc_md.pci_probe_mode function */
169 #define PCI_PROBE_NONE          -1      /* Don't look at this bus at all */
170 #define PCI_PROBE_NORMAL        0       /* Do normal PCI probing */
171 #define PCI_PROBE_DEVTREE       1       /* Instantiate from device tree */
172
173 #endif /* CONFIG_PPC64 */
174 #endif