blob: ab51f8d01e8d8346bad7fe23b62a8e0036694a04 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * Support for indirect PCI bridges.
3 *
4 * Copyright (C) 1998 Gabriel Paubert.
5 *
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.
10 */
11
12#include <common.h>
13
Wolfgang Denk3706ba12005-09-25 00:00:45 +020014#if (!defined(__I386__) && !defined(CONFIG_IXDP425))
wdenkaffae2b2002-08-17 09:36:01 +000015
16#include <asm/processor.h>
17#include <asm/io.h>
18#include <pci.h>
19
20#define cfg_read(val, addr, type, op) *val = op((type)(addr))
21#define cfg_write(val, addr, type, op) op((type *)(addr), (val))
22
wdenk289f9322005-01-12 00:15:14 +000023#ifdef CONFIG_IXP425
24extern unsigned char in_8 (volatile unsigned *addr);
25extern unsigned short in_le16 (volatile unsigned *addr);
26extern unsigned in_le32 (volatile unsigned *addr);
27extern void out_8 (volatile unsigned *addr, char val);
28extern void out_le16 (volatile unsigned *addr, unsigned short val);
29extern void out_le32 (volatile unsigned *addr, unsigned int val);
30#endif /* CONFIG_IXP425 */
31
wdenk5d232d02003-05-22 22:52:13 +000032#if defined(CONFIG_MPC8260)
wdenk4d75a502003-03-25 16:50:56 +000033#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
34static int \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020035indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenk4d75a502003-03-25 16:50:56 +000036 pci_dev_t dev, int offset, type val) \
37{ \
Kumar Galadffb70f2006-01-12 15:30:24 -060038 u32 b, d,f; \
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); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020042 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
wdenk4d75a502003-03-25 16:50:56 +000043 sync(); \
44 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020045 return 0; \
wdenk4d75a502003-03-25 16:50:56 +000046}
Ed Swarthout571f49f2007-07-11 14:52:01 -050047#elif defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
wdenk42d1f032003-10-15 23:53:47 +000048#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
49static int \
50indirect_##rw##_config_##size(struct pci_controller *hose, \
51 pci_dev_t dev, int offset, type val) \
52{ \
Kumar Galadffb70f2006-01-12 15:30:24 -060053 u32 b, d,f; \
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); \
Ed Swarthout571f49f2007-07-11 14:52:01 -050057 *(hose->cfg_addr) = dev | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000; \
wdenk42d1f032003-10-15 23:53:47 +000058 sync(); \
59 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
60 return 0; \
61}
Marian Balakowicz6c5879f2006-06-30 16:30:46 +020062#elif defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SPE)
wdenk3c74e322004-02-22 23:46:08 +000063#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
64static int \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020065indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenk3c74e322004-02-22 23:46:08 +000066 pci_dev_t dev, int offset, type val) \
67{ \
Kumar Galadffb70f2006-01-12 15:30:24 -060068 u32 b, d,f; \
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); \
wdenk3c74e322004-02-22 23:46:08 +000072 if (PCI_BUS(dev) > 0) \
73 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
74 else \
75 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
76 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020077 return 0; \
wdenk3c74e322004-02-22 23:46:08 +000078}
wdenk4d75a502003-03-25 16:50:56 +000079#else
wdenkaffae2b2002-08-17 09:36:01 +000080#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
81static int \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020082indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenkaffae2b2002-08-17 09:36:01 +000083 pci_dev_t dev, int offset, type val) \
84{ \
Kumar Galadffb70f2006-01-12 15:30:24 -060085 u32 b, d,f; \
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); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020089 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
wdenkaffae2b2002-08-17 09:36:01 +000090 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020091 return 0; \
wdenkaffae2b2002-08-17 09:36:01 +000092}
wdenk4d75a502003-03-25 16:50:56 +000093#endif
wdenkaffae2b2002-08-17 09:36:01 +000094
95#define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
96static int \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020097indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenkaffae2b2002-08-17 09:36:01 +000098 pci_dev_t dev, int offset, type val) \
99{ \
100 unsigned int msr = mfmsr(); \
101 mtmsr(msr & ~(MSR_EE | MSR_CE)); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200102 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
wdenkaffae2b2002-08-17 09:36:01 +0000103 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200104 out_le32(hose->cfg_addr, 0x00000000); \
wdenkaffae2b2002-08-17 09:36:01 +0000105 mtmsr(msr); \
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200106 return 0; \
wdenkaffae2b2002-08-17 09:36:01 +0000107}
108
109INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
110INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
111INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
112#ifdef CONFIG_405GP
113INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
114INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
115INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
116#else
117INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
118INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
119INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
120#endif
121
122void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
123{
124 pci_set_ops(hose,
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);
131
132 hose->cfg_addr = (unsigned int *) cfg_addr;
133 hose->cfg_data = (unsigned char *) cfg_data;
134}
135
Wolfgang Denk3706ba12005-09-25 00:00:45 +0200136#endif /* !__I386__ && !CONFIG_IXDP425 */