1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/*
* IXP PCI Init
*
* (C) Copyright 2011
* Michael Schwingen, michael@schwingen.org
* (C) Copyright 2004 eslab.whut.edu.cn
* Yue Hu(huyue_whut@yahoo.com.cn), Ligong Xue(lgxue@hotmail.com)
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <common.h>
#include <asm/processor.h>
#include <asm/io.h>
#include <pci.h>
#include <asm/arch/ixp425.h>
#include <asm/arch/ixp425pci.h>
DECLARE_GLOBAL_DATA_PTR;
static void non_prefetch_read(unsigned int addr, unsigned int cmd,
unsigned int *data);
static void non_prefetch_write(unsigned int addr, unsigned int cmd,
unsigned int data);
/*define the sub vendor and subsystem to be used */
#define IXP425_PCI_SUB_VENDOR_SYSTEM 0x00000000
#define PCI_MEMORY_BUS 0x00000000
#define PCI_MEMORY_PHY 0x00000000
#define PCI_MEMORY_SIZE 0x04000000
#define PCI_MEM_BUS 0x48000000
#define PCI_MEM_PHY 0x00000000
#define PCI_MEM_SIZE 0x04000000
#define PCI_IO_BUS 0x00000000
#define PCI_IO_PHY 0x00000000
#define PCI_IO_SIZE 0x00010000
/* build address value for config sycle */
static unsigned int pci_config_addr(pci_dev_t bdf, unsigned int reg)
{
unsigned int bus = PCI_BUS(bdf);
unsigned int dev = PCI_DEV(bdf);
unsigned int func = PCI_FUNC(bdf);
unsigned int addr;
if (bus) { /* secondary bus, use type 1 config cycle */
addr = bdf | (reg & ~3) | 1;
} else {
/*
primary bus, type 0 config cycle. address bits 31:28
specify the device 10:8 specify the function
*/
addr = BIT((31 - dev)) | (func << 8) | (reg & ~3);
}
return addr;
}
static int pci_config_status(void)
{
unsigned int regval;
regval = readl(PCI_CSR_BASE + PCI_ISR_OFFSET);
if ((regval & PCI_ISR_PFE) == 0)
return OK;
/* no device present, make sure that the master abort bit is reset */
writel(PCI_ISR_PFE, PCI_CSR_BASE + PCI_ISR_OFFSET);
return ERROR;
}
static int pci_ixp_hose_read_config_dword(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned int *val)
{
unsigned int retval;
unsigned int addr;
int stat;
debug("pci_ixp_hose_read_config_dword: bdf %x, reg %x", bdf, where);
/*Set the address to be read */
addr = pci_config_addr(bdf, where);
non_prefetch_read(addr, NP_CMD_CONFIGREAD, &retval);
*val = retval;
stat = pci_config_status();
if (stat < 0)
*val = -1;
debug("-> val %x, status %x\n", *val, stat);
return stat;
}
static int pci_ixp_hose_read_config_word(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned short *val)
{
unsigned int n;
unsigned int retval;
unsigned int addr;
unsigned int byteEnables;
int stat;
debug("pci_ixp_hose_read_config_word: bdf %x, reg %x", bdf, where);
n = where % 4;
/*byte enables are 4 bits active low, the position of each
bit maps to the byte that it enables */
byteEnables =
(~(BIT(n) | BIT((n + 1)))) &
IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
byteEnables = byteEnables << PCI_NP_CBE_BESL;
/*Set the address to be read */
addr = pci_config_addr(bdf, where);
non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
/*Pick out the word we are interested in */
*val = retval >> (8 * n);
stat = pci_config_status();
if (stat < 0)
*val = -1;
debug("-> val %x, status %x\n", *val, stat);
return stat;
}
static int pci_ixp_hose_read_config_byte(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned char *val)
{
unsigned int retval;
unsigned int n;
unsigned int byteEnables;
unsigned int addr;
int stat;
debug("pci_ixp_hose_read_config_byte: bdf %x, reg %x", bdf, where);
n = where % 4;
/*byte enables are 4 bits, active low, the position of each
bit maps to the byte that it enables */
byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
byteEnables = byteEnables << PCI_NP_CBE_BESL;
/*Set the address to be read */
addr = pci_config_addr(bdf, where);
non_prefetch_read(addr, byteEnables | NP_CMD_CONFIGREAD, &retval);
/*Pick out the byte we are interested in */
*val = retval >> (8 * n);
stat = pci_config_status();
if (stat < 0)
*val = -1;
debug("-> val %x, status %x\n", *val, stat);
return stat;
}
static int pci_ixp_hose_write_config_byte(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned char val)
{
unsigned int addr;
unsigned int byteEnables;
unsigned int n;
unsigned int ldata;
int stat;
debug("pci_ixp_hose_write_config_byte: bdf %x, reg %x, val %x",
bdf, where, val);
n = where % 4;
/*byte enables are 4 bits active low, the position of each
bit maps to the byte that it enables */
byteEnables = (~BIT(n)) & IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
byteEnables = byteEnables << PCI_NP_CBE_BESL;
ldata = val << (8 * n);
/*Set the address to be written */
addr = pci_config_addr(bdf, where);
non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
stat = pci_config_status();
debug("-> status %x\n", stat);
return stat;
}
static int pci_ixp_hose_write_config_word(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned short val)
{
unsigned int addr;
unsigned int byteEnables;
unsigned int n;
unsigned int ldata;
int stat;
debug("pci_ixp_hose_write_config_word: bdf %x, reg %x, val %x",
bdf, where, val);
n = where % 4;
/*byte enables are 4 bits active low, the position of each
bit maps to the byte that it enables */
byteEnables =
(~(BIT(n) | BIT((n + 1)))) &
IXP425_PCI_BOTTOM_NIBBLE_OF_LONG_MASK;
byteEnables = byteEnables << PCI_NP_CBE_BESL;
ldata = val << (8 * n);
/*Set the address to be written */
addr = pci_config_addr(bdf, where);
non_prefetch_write(addr, byteEnables | NP_CMD_CONFIGWRITE, ldata);
stat = pci_config_status();
debug("-> status %x\n", stat);
return stat;
}
static int pci_ixp_hose_write_config_dword(struct pci_controller *hose,
pci_dev_t bdf, int where, unsigned int val)
{
unsigned int addr;
int stat;
debug("pci_ixp_hose_write_config_dword: bdf %x, reg %x, val %x",
bdf, where, val);
/*Set the address to be written */
addr = pci_config_addr(bdf, where);
non_prefetch_write(addr, NP_CMD_CONFIGWRITE, val);
stat = pci_config_status();
debug("-> status %x\n", stat);
return stat;
}
static void non_prefetch_read(unsigned int addr,
unsigned int cmd, unsigned int *data)
{
writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
/*set up and execute the read */
writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
/*The result of the read is now in np_rdata */
*data = readl(PCI_CSR_BASE + PCI_NP_RDATA_OFFSET);
return;
}
static void non_prefetch_write(unsigned int addr,
unsigned int cmd, unsigned int data)
{
writel(addr, PCI_CSR_BASE + PCI_NP_AD_OFFSET);
/*set up the write */
writel(cmd, PCI_CSR_BASE + PCI_NP_CBE_OFFSET);
/*Execute the write by writing to NP_WDATA */
writel(data, PCI_CSR_BASE + PCI_NP_WDATA_OFFSET);
return;
}
static void crp_write(unsigned int offset, unsigned int data)
{
/*
* The CRP address register bit 16 indicates that we want to do a
* write
*/
writel(PCI_CRP_WRITE | offset, PCI_CSR_BASE + PCI_CRP_AD_CBE_OFFSET);
writel(data, PCI_CSR_BASE + PCI_CRP_WDATA_OFFSET);
}
void pci_ixp_init(struct pci_controller *hose)
{
unsigned int csr;
/*
* Specify that the AHB bus is operating in big endian mode. Set up
* byte lane swapping between little-endian PCI and the big-endian
* AHB bus
*/
#ifdef __ARMEB__
csr = PCI_CSR_ABE | PCI_CSR_PDS | PCI_CSR_ADS;
#else
csr = PCI_CSR_ABE;
#endif
writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
writel(0, PCI_CSR_BASE + PCI_INTEN_OFFSET);
/*
* We configure the PCI inbound memory windows to be
* 1:1 mapped to SDRAM
*/
crp_write(PCI_CFG_BASE_ADDRESS_0, 0x00000000);
crp_write(PCI_CFG_BASE_ADDRESS_1, 0x01000000);
crp_write(PCI_CFG_BASE_ADDRESS_2, 0x02000000);
crp_write(PCI_CFG_BASE_ADDRESS_3, 0x03000000);
/*
* Enable CSR window at 64 MiB to allow PCI masters
* to continue prefetching past 64 MiB boundary.
*/
crp_write(PCI_CFG_BASE_ADDRESS_4, 0x04000000);
/*
* Enable the IO window to be way up high, at 0xfffffc00
*/
crp_write(PCI_CFG_BASE_ADDRESS_5, 0xfffffc01);
/*Setup PCI-AHB and AHB-PCI address mappings */
writel(0x00010203, PCI_CSR_BASE + PCI_AHBMEMBASE_OFFSET);
writel(0x00000000, PCI_CSR_BASE + PCI_AHBIOBASE_OFFSET);
writel(0x48494a4b, PCI_CSR_BASE + PCI_PCIMEMBASE_OFFSET);
crp_write(PCI_CFG_SUB_VENDOR_ID, IXP425_PCI_SUB_VENDOR_SYSTEM);
crp_write(PCI_CFG_COMMAND, PCI_CFG_CMD_MAE | PCI_CFG_CMD_BME);
udelay(1000);
/* clear error bits in status register */
writel(PCI_ISR_PSE | PCI_ISR_PFE | PCI_ISR_PPE | PCI_ISR_AHBE,
PCI_CSR_BASE + PCI_ISR_OFFSET);
/*
* Set Initialize Complete in PCI Control Register: allow IXP4XX to
* respond to PCI configuration cycles.
*/
csr |= PCI_CSR_IC;
writel(csr, PCI_CSR_BASE + PCI_CSR_OFFSET);
hose->first_busno = 0;
hose->last_busno = 0;
/* System memory space */
pci_set_region(hose->regions + 0,
PCI_MEMORY_BUS,
PCI_MEMORY_PHY, PCI_MEMORY_SIZE, PCI_REGION_SYS_MEMORY);
/* PCI memory space */
pci_set_region(hose->regions + 1,
PCI_MEM_BUS,
PCI_MEM_PHY, PCI_MEM_SIZE, PCI_REGION_MEM);
/* PCI I/O space */
pci_set_region(hose->regions + 2,
PCI_IO_BUS, PCI_IO_PHY, PCI_IO_SIZE, PCI_REGION_IO);
hose->region_count = 3;
pci_set_ops(hose,
pci_ixp_hose_read_config_byte,
pci_ixp_hose_read_config_word,
pci_ixp_hose_read_config_dword,
pci_ixp_hose_write_config_byte,
pci_ixp_hose_write_config_word,
pci_ixp_hose_write_config_dword);
pci_register_hose(hose);
hose->last_busno = pci_hose_scan(hose);
}
|