blob: efa13a2393888020d478412c773120dd99a90cf2 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * Support for indirect PCI bridges.
3 *
4 * Copyright (C) 1998 Gabriel Paubert.
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00007 */
8
9#include <common.h>
10
Michael Schwingenb9de2fa2011-05-23 00:00:12 +020011#if !defined(__I386__)
wdenkaffae2b2002-08-17 09:36:01 +000012
13#include <asm/processor.h>
14#include <asm/io.h>
15#include <pci.h>
16
17#define cfg_read(val, addr, type, op) *val = op((type)(addr))
18#define cfg_write(val, addr, type, op) op((type *)(addr), (val))
19
Heiko Schocher71cb3e92017-06-07 17:33:10 +020020#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
wdenk9c53f402003-10-15 23:53:47 +000021#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
22static int \
23indirect_##rw##_config_##size(struct pci_controller *hose, \
24 pci_dev_t dev, int offset, type val) \
25{ \
Kumar Gala233b9922006-01-12 15:30:24 -060026 u32 b, d,f; \
27 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
28 b = b - hose->first_busno; \
29 dev = PCI_BDF(b, d, f); \
Ed Swarthout09489ff2007-07-11 14:52:01 -050030 *(hose->cfg_addr) = dev | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000; \
wdenk9c53f402003-10-15 23:53:47 +000031 sync(); \
32 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
33 return 0; \
34}
Felix Radenskybcaaeb82010-01-23 01:35:24 +020035#elif defined(CONFIG_440GX) || defined(CONFIG_440GP) || defined(CONFIG_440SP) || \
36 defined(CONFIG_440SPE) || defined(CONFIG_460EX) || defined(CONFIG_460GT)
wdenk56ed43e2004-02-22 23:46:08 +000037#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
38static int \
Wolfgang Denka1be4762008-05-20 16:00:29 +020039indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenk56ed43e2004-02-22 23:46:08 +000040 pci_dev_t dev, int offset, type val) \
41{ \
Kumar Gala233b9922006-01-12 15:30:24 -060042 u32 b, d,f; \
43 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
44 b = b - hose->first_busno; \
45 dev = PCI_BDF(b, d, f); \
wdenk56ed43e2004-02-22 23:46:08 +000046 if (PCI_BUS(dev) > 0) \
47 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000001); \
48 else \
49 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
50 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020051 return 0; \
wdenk56ed43e2004-02-22 23:46:08 +000052}
wdenk28536032003-03-25 16:50:56 +000053#else
54#define INDIRECT_PCI_OP(rw, size, type, op, mask) \
55static int \
Wolfgang Denka1be4762008-05-20 16:00:29 +020056indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenk28536032003-03-25 16:50:56 +000057 pci_dev_t dev, int offset, type val) \
58{ \
Kumar Gala233b9922006-01-12 15:30:24 -060059 u32 b, d,f; \
60 b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
61 b = b - hose->first_busno; \
62 dev = PCI_BDF(b, d, f); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020063 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
wdenk28536032003-03-25 16:50:56 +000064 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020065 return 0; \
wdenk28536032003-03-25 16:50:56 +000066}
67#endif
wdenkaffae2b2002-08-17 09:36:01 +000068
69#define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
70static int \
Wolfgang Denka1be4762008-05-20 16:00:29 +020071indirect_##rw##_config_##size(struct pci_controller *hose, \
wdenkaffae2b2002-08-17 09:36:01 +000072 pci_dev_t dev, int offset, type val) \
73{ \
74 unsigned int msr = mfmsr(); \
75 mtmsr(msr & ~(MSR_EE | MSR_CE)); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020076 out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
wdenkaffae2b2002-08-17 09:36:01 +000077 cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020078 out_le32(hose->cfg_addr, 0x00000000); \
wdenkaffae2b2002-08-17 09:36:01 +000079 mtmsr(msr); \
Wolfgang Denka1be4762008-05-20 16:00:29 +020080 return 0; \
wdenkaffae2b2002-08-17 09:36:01 +000081}
82
83INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
84INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
85INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
86#ifdef CONFIG_405GP
87INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
88INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
89INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
90#else
91INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
92INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
93INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
94#endif
95
96void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
97{
98 pci_set_ops(hose,
99 indirect_read_config_byte,
100 indirect_read_config_word,
101 indirect_read_config_dword,
102 indirect_write_config_byte,
103 indirect_write_config_word,
104 indirect_write_config_dword);
105
106 hose->cfg_addr = (unsigned int *) cfg_addr;
107 hose->cfg_data = (unsigned char *) cfg_data;
108}
109
Michael Schwingenb9de2fa2011-05-23 00:00:12 +0200110#endif /* !__I386__ */