2 * Support for indirect PCI bridges.
4 * Copyright (C) 1998 Gabriel Paubert.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/pci.h>
14 #include <linux/delay.h>
15 #include <linux/string.h>
16 #include <linux/init.h>
19 #include <asm/pci-bridge.h>
22 indirect_read_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
25 struct pci_controller
*hose
= pci_bus_to_host(bus
);
26 volatile void __iomem
*cfg_data
;
30 if (hose
->indirect_type
& INDIRECT_TYPE_NO_PCIE_LINK
) {
31 if (bus
->number
!= hose
->first_busno
)
32 return PCIBIOS_DEVICE_NOT_FOUND
;
34 return PCIBIOS_DEVICE_NOT_FOUND
;
37 if (hose
->indirect_type
& INDIRECT_TYPE_SET_CFG_TYPE
)
38 if (bus
->number
!= hose
->first_busno
)
41 bus_no
= (bus
->number
== hose
->first_busno
) ?
42 hose
->self_busno
: bus
->number
;
44 if (hose
->indirect_type
& INDIRECT_TYPE_EXT_REG
)
45 reg
= ((offset
& 0xf00) << 16) | (offset
& 0xfc);
47 reg
= offset
& 0xfc; /* Only 3 bits for function */
49 if (hose
->indirect_type
& INDIRECT_TYPE_BIG_ENDIAN
)
50 out_be32(hose
->cfg_addr
, (0x80000000 | (bus_no
<< 16) |
51 (devfn
<< 8) | reg
| cfg_type
));
53 out_le32(hose
->cfg_addr
, (0x80000000 | (bus_no
<< 16) |
54 (devfn
<< 8) | reg
| cfg_type
));
57 * Note: the caller has already checked that offset is
58 * suitably aligned and that len is 1, 2 or 4.
60 cfg_data
= hose
->cfg_data
+ (offset
& 3); /* Only 3 bits for function */
63 *val
= in_8(cfg_data
);
66 *val
= in_le16(cfg_data
);
69 *val
= in_le32(cfg_data
);
72 return PCIBIOS_SUCCESSFUL
;
76 indirect_write_config(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
79 struct pci_controller
*hose
= pci_bus_to_host(bus
);
80 volatile void __iomem
*cfg_data
;
84 if (hose
->indirect_type
& INDIRECT_TYPE_NO_PCIE_LINK
) {
85 if (bus
->number
!= hose
->first_busno
)
86 return PCIBIOS_DEVICE_NOT_FOUND
;
88 return PCIBIOS_DEVICE_NOT_FOUND
;
91 if (hose
->indirect_type
& INDIRECT_TYPE_SET_CFG_TYPE
)
92 if (bus
->number
!= hose
->first_busno
)
95 bus_no
= (bus
->number
== hose
->first_busno
) ?
96 hose
->self_busno
: bus
->number
;
98 if (hose
->indirect_type
& INDIRECT_TYPE_EXT_REG
)
99 reg
= ((offset
& 0xf00) << 16) | (offset
& 0xfc);
103 if (hose
->indirect_type
& INDIRECT_TYPE_BIG_ENDIAN
)
104 out_be32(hose
->cfg_addr
, (0x80000000 | (bus_no
<< 16) |
105 (devfn
<< 8) | reg
| cfg_type
));
107 out_le32(hose
->cfg_addr
, (0x80000000 | (bus_no
<< 16) |
108 (devfn
<< 8) | reg
| cfg_type
));
110 /* suppress setting of PCI_PRIMARY_BUS */
111 if (hose
->indirect_type
& INDIRECT_TYPE_SURPRESS_PRIMARY_BUS
)
112 if ((offset
== PCI_PRIMARY_BUS
) &&
113 (bus
->number
== hose
->first_busno
))
116 /* Workaround for PCI_28 Errata in 440EPx/GRx */
117 if ((hose
->indirect_type
& INDIRECT_TYPE_BROKEN_MRM
) &&
118 offset
== PCI_CACHE_LINE_SIZE
) {
123 * Note: the caller has already checked that offset is
124 * suitably aligned and that len is 1, 2 or 4.
126 cfg_data
= hose
->cfg_data
+ (offset
& 3);
129 out_8(cfg_data
, val
);
132 out_le16(cfg_data
, val
);
135 out_le32(cfg_data
, val
);
139 return PCIBIOS_SUCCESSFUL
;
142 static struct pci_ops indirect_pci_ops
= {
143 .read
= indirect_read_config
,
144 .write
= indirect_write_config
,
148 setup_indirect_pci(struct pci_controller
*hose
,
149 resource_size_t cfg_addr
,
150 resource_size_t cfg_data
, u32 flags
)
152 resource_size_t base
= cfg_addr
& PAGE_MASK
;
155 mbase
= ioremap(base
, PAGE_SIZE
);
156 hose
->cfg_addr
= mbase
+ (cfg_addr
& ~PAGE_MASK
);
157 if ((cfg_data
& PAGE_MASK
) != base
)
158 mbase
= ioremap(cfg_data
& PAGE_MASK
, PAGE_SIZE
);
159 hose
->cfg_data
= mbase
+ (cfg_data
& ~PAGE_MASK
);
160 hose
->ops
= &indirect_pci_ops
;
161 hose
->indirect_type
= flags
;