GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / powerpc / sysdev / indirect_pci.c
blob0850bbdc2c96b4e109d87125a79a69a77690a8cb
1 /*
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>
18 #include <asm/io.h>
19 #include <asm/prom.h>
20 #include <asm/pci-bridge.h>
21 #include <asm/machdep.h>
23 static int
24 indirect_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
25 int len, u32 *val)
27 struct pci_controller *hose = pci_bus_to_host(bus);
28 volatile void __iomem *cfg_data;
29 u8 cfg_type = 0;
30 u32 bus_no, reg;
32 if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
33 if (bus->number != hose->first_busno)
34 return PCIBIOS_DEVICE_NOT_FOUND;
35 if (devfn != 0)
36 return PCIBIOS_DEVICE_NOT_FOUND;
39 if (ppc_md.pci_exclude_device)
40 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
41 return PCIBIOS_DEVICE_NOT_FOUND;
43 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
44 if (bus->number != hose->first_busno)
45 cfg_type = 1;
47 bus_no = (bus->number == hose->first_busno) ?
48 hose->self_busno : bus->number;
50 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
51 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
52 else
53 reg = offset & 0xfc;
55 if (hose->indirect_type & PPC_INDIRECT_TYPE_BIG_ENDIAN)
56 out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
57 (devfn << 8) | reg | cfg_type));
58 else
59 out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
60 (devfn << 8) | reg | cfg_type));
63 * Note: the caller has already checked that offset is
64 * suitably aligned and that len is 1, 2 or 4.
66 cfg_data = hose->cfg_data + (offset & 3);
67 switch (len) {
68 case 1:
69 *val = in_8(cfg_data);
70 break;
71 case 2:
72 *val = in_le16(cfg_data);
73 break;
74 default:
75 *val = in_le32(cfg_data);
76 break;
78 return PCIBIOS_SUCCESSFUL;
81 static int
82 indirect_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
83 int len, u32 val)
85 struct pci_controller *hose = pci_bus_to_host(bus);
86 volatile void __iomem *cfg_data;
87 u8 cfg_type = 0;
88 u32 bus_no, reg;
90 if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
91 if (bus->number != hose->first_busno)
92 return PCIBIOS_DEVICE_NOT_FOUND;
93 if (devfn != 0)
94 return PCIBIOS_DEVICE_NOT_FOUND;
97 if (ppc_md.pci_exclude_device)
98 if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
99 return PCIBIOS_DEVICE_NOT_FOUND;
101 if (hose->indirect_type & PPC_INDIRECT_TYPE_SET_CFG_TYPE)
102 if (bus->number != hose->first_busno)
103 cfg_type = 1;
105 bus_no = (bus->number == hose->first_busno) ?
106 hose->self_busno : bus->number;
108 if (hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG)
109 reg = ((offset & 0xf00) << 16) | (offset & 0xfc);
110 else
111 reg = offset & 0xfc;
113 if (hose->indirect_type & PPC_INDIRECT_TYPE_BIG_ENDIAN)
114 out_be32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
115 (devfn << 8) | reg | cfg_type));
116 else
117 out_le32(hose->cfg_addr, (0x80000000 | (bus_no << 16) |
118 (devfn << 8) | reg | cfg_type));
120 /* surpress setting of PCI_PRIMARY_BUS */
121 if (hose->indirect_type & PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS)
122 if ((offset == PCI_PRIMARY_BUS) &&
123 (bus->number == hose->first_busno))
124 val &= 0xffffff00;
126 if ((hose->indirect_type & PPC_INDIRECT_TYPE_BROKEN_MRM) &&
127 offset == PCI_CACHE_LINE_SIZE) {
128 val = 0;
132 * Note: the caller has already checked that offset is
133 * suitably aligned and that len is 1, 2 or 4.
135 cfg_data = hose->cfg_data + (offset & 3);
136 switch (len) {
137 case 1:
138 out_8(cfg_data, val);
139 break;
140 case 2:
141 out_le16(cfg_data, val);
142 break;
143 default:
144 out_le32(cfg_data, val);
145 break;
147 return PCIBIOS_SUCCESSFUL;
150 static struct pci_ops indirect_pci_ops =
152 .read = indirect_read_config,
153 .write = indirect_write_config,
156 void __init
157 setup_indirect_pci(struct pci_controller* hose,
158 resource_size_t cfg_addr,
159 resource_size_t cfg_data, u32 flags)
161 resource_size_t base = cfg_addr & PAGE_MASK;
162 void __iomem *mbase;
164 mbase = ioremap(base, PAGE_SIZE);
165 hose->cfg_addr = mbase + (cfg_addr & ~PAGE_MASK);
166 if ((cfg_data & PAGE_MASK) != base)
167 mbase = ioremap(cfg_data & PAGE_MASK, PAGE_SIZE);
168 hose->cfg_data = mbase + (cfg_data & ~PAGE_MASK);
169 hose->ops = &indirect_pci_ops;
170 hose->indirect_type = flags;