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.
14 #if (!defined(__I386__) && !defined(CONFIG_IXDP425))
16 #include <asm/processor.h>
20 #define cfg_read(val, addr, type, op) *val = op((type)(addr))
21 #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
24 extern unsigned char in_8 (volatile unsigned *addr);
25 extern unsigned short in_le16 (volatile unsigned *addr);
26 extern unsigned in_le32 (volatile unsigned *addr);
27 extern void out_8 (volatile unsigned *addr, char val);
28 extern void out_le16 (volatile unsigned *addr, unsigned short val);
29 extern void out_le32 (volatile unsigned *addr, unsigned int val);
30 #endif /* CONFIG_IXP425 */
32 #if defined(CONFIG_MPC8260)
33 #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
35 indirect_##rw##_config_##size(struct pci_controller *hose, \
36 pci_dev_t dev, int offset, type val) \
39 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
40 b = b - hose->first_busno; \
41 dev = PCI_BDF(b, d, f); \
42 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
44 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
47 #elif defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
48 #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
50 indirect_##rw##_config_##size(struct pci_controller *hose, \
51 pci_dev_t dev, int offset, type val) \
54 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
55 b = b - hose->first_busno; \
56 dev = PCI_BDF(b, d, f); \
57 *(hose->cfg_addr) = dev | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000; \
59 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
62 #elif defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SPE)
63 #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
65 indirect_##rw##_config_##size(struct pci_controller *hose, \
66 pci_dev_t dev, int offset, type val) \
69 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
70 b = b - hose->first_busno; \
71 dev = PCI_BDF(b, d, f); \
72 if (PCI_BUS(dev) > 0) \
73 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
75 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
76 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
80 #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
82 indirect_##rw##_config_##size(struct pci_controller *hose, \
83 pci_dev_t dev, int offset, type val) \
86 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
87 b = b - hose->first_busno; \
88 dev = PCI_BDF(b, d, f); \
89 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
90 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
95 #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
97 indirect_##rw##_config_##size(struct pci_controller *hose, \
98 pci_dev_t dev, int offset, type val) \
100 unsigned int msr = mfmsr(); \
101 mtmsr(msr & ~(MSR_EE | MSR_CE)); \
102 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
103 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
104 out_le32(hose->cfg_addr, 0x00000000); \
109 INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
110 INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
111 INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
113 INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
114 INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
115 INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
117 INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
118 INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
119 INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
122 void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
125 indirect_read_config_byte,
126 indirect_read_config_word,
127 indirect_read_config_dword,
128 indirect_write_config_byte,
129 indirect_write_config_word,
130 indirect_write_config_dword);
132 hose->cfg_addr = (unsigned int *) cfg_addr;
133 hose->cfg_data = (unsigned char *) cfg_data;
136 #endif /* !__I386__ && !CONFIG_IXDP425 */