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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
/*
* arch/arm/mach-tegra/pci-enum.c
*
* Code to enumerate the PCI devices on the PCI bus. Unlike x86 we cannot
* rely on BIOS to allocate the PCIe resources for the devices.
*
* Copyright (c) 2008-2009, NVIDIA Corporation.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <mach/pci.h>
#include <mach/iomap.h>
#include <mach/irqs.h>
#include <linux/delay.h>
#include <linux/ioport.h>
struct pci_tegra_device
{
/* Bus number */
u8 bus;
/* Device + function encoding.
* Use macros PCI_DEVFN/PCI_SLOT/PCI_FUNC to encode and decode
* */
u32 devfn;
/* Secondary bus nummber. Non-zero only for bridge devices. */
u32 sec_bus;
/* Subordinate bus number. Non-zero only for the bridge devices. */
u32 sub_bus;
/* Device ID/vendor ID of the PCI device/bridge.
* Upper 16 bits are device ID and lower 16 bits are vendor ID.
*/
u32 id;
/* For a bridge device only 3 bars are used.
*/
#define PCI_BRIDGE_IO_RES 0
#define PCI_BRIDGE_MEM_RES 1
#define PCI_BRIDGE_PREFETCH_RES 2
/* Here we are limiting to the standard PCI resources */
struct resource res[PCI_STD_RESOURCE_END + 1];
bool disabled;
struct pci_tegra_device *parent;
struct pci_tegra_device *next;
struct pci_tegra_device *prev;
struct pci_tegra_device *child;
bool root_port;
};
#define TEGRA_MAX_PCI_DEVICES 64
static struct pci_tegra_device pci_devices[TEGRA_MAX_PCI_DEVICES];
static int max_devices;
static struct pci_tegra_device *pci_root;
static u32 pci_tegra_io_base;
static u32 pci_tegra_mem_base;
static u32 pci_tegra_prefetch_base;
static u32 pci_tegra_io_limt;
static u32 pci_tegra_mem_limit;
static u32 pci_tegra_prefetch_limit;
static void pci_tegra_print_device_tree(struct pci_tegra_device *dev);
static void pcie_scanbus(struct pci_tegra_device *dev_parent);
static void pci_tegra_allocate_resources(struct pci_tegra_device *dev);
static struct pci_tegra_device *alloc_pci_tegra_device(void)
{
static u32 index = 0;
struct pci_tegra_device *dev;
if (index == 0)
memset(pci_devices, 0, sizeof(pci_devices));
dev = &pci_devices[index];
index++;
max_devices = index;
return dev;
}
static inline void pci_conf_write8(u8 bus, u32 devfn, u32 where , u8 val)
{
u32 addr;
u32 temp;
addr = (u32)pci_tegra_config_addr(bus, devfn, where);
pr_err("Issuing pci_conf_write8 at addr 0x%x with data 0x%x\n",
addr, val);
temp = readl((addr & ~0x3));
temp &= ~(0xff << ((addr & 0x3) * 8));
temp |= (u32)val << ((addr & 0x3) * 8);
writel(temp, (addr & ~0x3));
}
static inline void pci_conf_write16(u8 bus, u32 devfn, u32 where, u16 val)
{
u32 addr;
u32 temp;
BUG_ON(where & 0x1);
addr = (u32)pci_tegra_config_addr(bus, devfn, where);
pr_err("Issuing pci_conf_write16 at addr 0x%x with data 0x%x\n",
addr, val);
temp = readl((addr & ~0x3));
temp &= ~(0xffff << ((addr& 0x3) * 8));
temp |= (u32)val << ((addr & 0x3) * 8);
writel(temp, (addr & ~0x3));
}
static inline void pci_conf_write32(u8 bus, u32 devfn, u32 where, u32 val)
{
u32 addr;
BUG_ON(where & 0x3);
addr = (u32)pci_tegra_config_addr(bus, devfn, where);
pr_err("Issuing pci_conf_write32 at addr 0x%x with data 0x%x\n",
addr, val);
writel(val, addr);
}
static inline u8 pci_conf_read8(u8 bus, u32 devfn, u32 where)
{
u32 temp;
u32 addr;
addr = (u32)pci_tegra_config_addr(bus, devfn, where);
pr_err("Issuing pci_conf_read8 at 0x%x\n", addr);
temp = readl(addr & ~0x3);
temp >>= 8 * (addr & 3);
temp &= 0xff;
pr_err("pci_conf_read8 at 0x%x = %d\n", addr, temp);
return (u8)temp;
}
static u32 pci_conf_read32(u8 bus, u32 devfn, u32 where)
{
u32 temp;
BUG_ON(where & 0x3);
pr_err("Issuing pci_conf_read32 at 0x%x\n",
(u32)(pci_tegra_config_addr(bus, devfn, where)));
temp = readl(pci_tegra_config_addr(bus, devfn, where));
pr_err("pci_conf_read32 at 0x%x = %d\n", where, temp);
return temp;
}
static void pcie_scanbus(struct pci_tegra_device *dev_parent)
{
u8 subordinate_bus;
u8 hdr_type;
u8 next_bus_number;
u32 device = 0;
u32 id;
struct pci_tegra_device *dev;
u32 retry_count;
next_bus_number = dev_parent->sec_bus;
next_device:
retry_count = 6;
if (device == 0x20) {
/* Termination condition: Max number of devices reached.
* PCIe bus segment can only have 32 devices.
* */
dev_parent->sub_bus = next_bus_number;
if (!dev_parent->root_port) {
/* Change the subordinate bus-number to the actual
* value of all buses on the hierarcy.
*
* Do this execpt for the root port.
*/
pci_conf_write8(dev_parent->bus, dev_parent->devfn,
PCI_SUBORDINATE_BUS, next_bus_number);
}
return;
}
if (dev_parent->root_port && device != 0) {
/* Sepcial Exit condition for root port.
* Root port only connect to one bridge or device.
*/
dev_parent->sub_bus = dev_parent->sec_bus;
return;
}
while (--retry_count) {
id = pci_conf_read32(dev_parent->sec_bus,
PCI_DEVFN(device, 0), 0);
if (id != 0xFFFFFFFF)
{
/* Found a valid device, break. Otherwise, retry a couple of
* times. It is possible that the bridges can take some time
* to settle and it will take couple of transcations to find
* the devcies behind the bridge.
* */
/* FIXME: What should be the delay? */
msleep(100);
break;
}
}
if (id == 0xFFFFFFFF) {
/* Invalid device. Skip that one and look for next device */
device++;
goto next_device;
}
dev = alloc_pci_tegra_device();
/* Fill the device information */
dev->parent = dev_parent;
dev->id = id;
dev->bus = dev_parent->sec_bus;
dev->devfn = PCI_DEVFN(device, 0);
if (dev_parent->child == NULL) {
dev_parent->child = dev;
dev->prev = NULL;
} else {
/* Add dev to the list of devices on the same bus */
struct pci_tegra_device *temp;
temp = dev_parent->child;
BUG_ON(temp != NULL);
while (temp->next != NULL)
temp = temp->next;
temp->next = dev;
dev->prev = temp;
}
hdr_type = pci_conf_read8(dev->bus, dev->devfn, PCI_HEADER_TYPE);
if ((hdr_type & 0x7f) == 0x1) {
/* Bridge device */
/* Temporarily assign 0xff for the subordinate bus number as
* we don't * know how many devices are present behind this
* bridge.
* */
subordinate_bus = 0xff;
dev->sec_bus = next_bus_number + 1;
pci_conf_write8(dev->bus, dev->devfn, PCI_PRIMARY_BUS,
dev_parent->sec_bus);
pci_conf_write8(dev->bus, dev->devfn, PCI_SECONDARY_BUS,
dev->sec_bus);
pci_conf_write8(dev->bus, dev->devfn, PCI_SUBORDINATE_BUS,
subordinate_bus);
/* Scan all the buses behind this bridge */
pcie_scanbus(dev);
next_bus_number = dev->sub_bus;
} else if ((hdr_type & 0x7f) == 0x0) {
/* PCI endpoint - Can be single function or multie function */
pr_info("PCI endpoint (0x%x) is on bus = %d, device = %d\n",
id, dev_parent->sec_bus, device);
} else if ((hdr_type & 0x7f) == 0x2) {
/* PC card device - Not handled */
BUG();
} else {
BUG();
}
device++;
goto next_device;
}
static void pci_tegra_enumerate_root_port(int rp)
{
struct pci_tegra_device *root;
u32 reg;
root = alloc_pci_tegra_device();
if (pci_root) {
pci_root->next = root;
root->bus = pci_root->sub_bus + 1;
} else {
pci_root = root;
root->bus = 0;
}
root->sec_bus = root->bus + 1;
root->root_port = true;
/* Set the Inital value to the max bus number */
root->sub_bus = 0xff;
root->id = pci_tegra_rp_readl(0, rp);
pci_tegra_rp_writeb(root->bus, PCI_PRIMARY_BUS, rp);
pci_tegra_rp_writeb(root->sec_bus, PCI_SECONDARY_BUS, rp);
pci_tegra_rp_writeb(root->sub_bus, PCI_SUBORDINATE_BUS, rp);
/* Just assigns the bus numbers and sets up the SW hirerarchy */
pcie_scanbus(root);
/* Write the udpated root port subordinate bus number */
pci_tegra_rp_writeb(root->sub_bus, PCI_SUBORDINATE_BUS, rp);
pci_tegra_allocate_resources(root);
/* IO base and limits */
reg = root->res[PCI_BRIDGE_IO_RES].start;
reg = ALIGN(reg, 0x1000);
pci_tegra_rp_writeb((((reg & 0xf000) >> 8) | PCI_IO_RANGE_TYPE_32),
PCI_IO_BASE, rp);
pci_tegra_rp_writew(reg>>16, PCI_IO_BASE_UPPER16, rp);
reg = root->res[PCI_BRIDGE_IO_RES].end;
reg = ALIGN(reg, 0x1000) - 1;
pci_tegra_rp_writeb((((reg & 0xf000) >> 8) | PCI_IO_RANGE_TYPE_32),
PCI_IO_LIMIT, rp);
pci_tegra_rp_writew(reg>>16, PCI_IO_LIMIT_UPPER16, rp);
/* Memory base and limits */
if (root->res[PCI_BRIDGE_MEM_RES].start != root->res[PCI_BRIDGE_MEM_RES].end) {
reg = root->res[PCI_BRIDGE_MEM_RES].start;
reg = ALIGN(reg, 0x100000);
pci_tegra_rp_writew(reg >> 16, PCI_MEMORY_BASE, rp);
reg = root->res[PCI_BRIDGE_MEM_RES].end;
reg = ALIGN(reg, 0x100000) - 1;
pci_tegra_rp_writew(reg >> 16, PCI_MEMORY_LIMIT, rp);
} else {
pci_tegra_rp_writew(0xffff, PCI_MEMORY_BASE, rp);
pci_tegra_rp_writew(0x0000, PCI_MEMORY_LIMIT, rp);
}
/* Prefetch base and limit - 32 bit addressing */
if (root->res[PCI_BRIDGE_PREFETCH_RES].start != root->res[PCI_BRIDGE_PREFETCH_RES].end) {
reg = root->res[PCI_BRIDGE_PREFETCH_RES].start;
reg = ALIGN(reg, 0x100000);
pci_tegra_rp_writew(reg >> 16, PCI_PREF_MEMORY_BASE, rp);
reg = root->res[PCI_BRIDGE_PREFETCH_RES].end;
reg = ALIGN(reg, 0x100000) - 1;
pci_tegra_rp_writew(reg >> 16, PCI_PREF_MEMORY_LIMIT, rp);
} else {
pci_tegra_rp_writew(0xffff, PCI_PREF_MEMORY_BASE, rp);
pci_tegra_rp_writew(0, PCI_PREF_MEMORY_LIMIT, rp);
}
pci_tegra_rp_writel(0, PCI_PREF_BASE_UPPER32, rp);
pci_tegra_rp_writel(0, PCI_PREF_LIMIT_UPPER32, rp);
reg = 0;
reg |= PCI_COMMAND_IO;
reg |= PCI_COMMAND_MEMORY;
reg |= PCI_COMMAND_MASTER;
reg |= PCI_COMMAND_SERR;
pci_tegra_rp_writew(reg, PCI_COMMAND, rp);
}
static void pci_tegra_setup_pci_bridge(struct pci_tegra_device *dev)
{
u32 reg;
dev->res[PCI_BRIDGE_IO_RES].end = pci_tegra_io_base;
dev->res[PCI_BRIDGE_MEM_RES].end = pci_tegra_mem_base;
dev->res[PCI_BRIDGE_PREFETCH_RES].end =
pci_tegra_prefetch_base;
/* Only set here for the non-root port devices */
if (dev->root_port)
return;
/* IO base and limits */
reg = dev->res[PCI_BRIDGE_IO_RES].start;
reg = ALIGN(reg, 0x1000);
pci_conf_write8(dev->bus, dev->devfn, PCI_IO_BASE,
(((reg & 0xf000) >> 8) | PCI_IO_RANGE_TYPE_32));
pci_conf_write16(dev->bus, dev->devfn, PCI_IO_BASE_UPPER16, reg>>16);
reg = dev->res[PCI_BRIDGE_IO_RES].end;
reg = ALIGN(reg, 0x1000);
pci_conf_write8(dev->bus, dev->devfn, PCI_IO_LIMIT,
(((reg & 0xf000) >> 8) | PCI_IO_RANGE_TYPE_32));
pci_conf_write16(dev->bus, dev->devfn, PCI_IO_LIMIT_UPPER16, reg>>16);
/* Memory base and limits */
if (dev->res[PCI_BRIDGE_MEM_RES].start != dev->res[PCI_BRIDGE_MEM_RES].end) {
reg = dev->res[PCI_BRIDGE_MEM_RES].start;
reg = ALIGN(reg, 0x100000);
pci_conf_write16(dev->bus, dev->devfn, PCI_MEMORY_BASE, reg >> 16);
reg = dev->res[PCI_BRIDGE_MEM_RES].end;
reg = ALIGN(reg, 0x100000);
pci_conf_write16(dev->bus, dev->devfn, PCI_MEMORY_LIMIT, reg >> 16);
} else {
pci_conf_write16(dev->bus, dev->devfn, PCI_MEMORY_BASE, 0xffff);
pci_conf_write16(dev->bus, dev->devfn, PCI_MEMORY_LIMIT, 0);
}
/* Prefetch base and limit - 32 bit addressing */
if (dev->res[PCI_BRIDGE_PREFETCH_RES].start != dev->res[PCI_BRIDGE_PREFETCH_RES].end) {
reg = dev->res[PCI_BRIDGE_PREFETCH_RES].start;
reg = ALIGN(reg, 0x100000);
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_MEMORY_BASE,
reg >> 16);
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_BASE_UPPER32, 0);
reg = dev->res[PCI_BRIDGE_PREFETCH_RES].end;
reg = ALIGN(reg, 0x100000);
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_MEMORY_LIMIT,
reg >> 16);
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_LIMIT_UPPER32, 0);
} else {
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_MEMORY_BASE, 0xffff);
pci_conf_write16(dev->bus, dev->devfn, PCI_PREF_MEMORY_LIMIT, 0);
}
reg = 0;
reg |= PCI_COMMAND_IO;
reg |= PCI_COMMAND_MEMORY;
reg |= PCI_COMMAND_MASTER;
reg |= PCI_COMMAND_SERR;
pci_conf_write16(dev->bus, dev->devfn, PCI_COMMAND, reg);
pci_conf_write8(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, INT_PCIE_INTR);
pci_conf_write8(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 0xa);
}
static void pci_tegra_setup_pci_device(struct pci_tegra_device *dev)
{
u8 flags;
u32 bar_index;
u32 reg;
u32 addr;
for (bar_index = 0x0; bar_index <= PCI_STD_RESOURCE_END;
bar_index ++) {
u32 size;
pci_conf_write32(dev->bus, dev->devfn, bar_index * 4
+ PCI_BASE_ADDRESS_0, 0xFFFFFFFFUL);
size = pci_conf_read32(dev->bus, dev->devfn, bar_index * 4
+ PCI_BASE_ADDRESS_0);
if (size == 0xFFFFFFFFUL) continue;
if (size == 0) continue; /* A broken device? */
flags = (size & 0x000f);
/* Size align the addr and write that BAR offset */
if (flags & 0x1) {
size &= ~0xF; /* Ignore the last 4 bits */
/* some devices hardwire the high bits of IO bars to 0
* So, ignore those bits.
*/
size |= 0xffff0000;
size = ~size + 1; /* Do the 1's complement */
addr = ALIGN(pci_tegra_io_base, size);
if (addr + size > pci_tegra_io_limt) {
pr_err("pci_tegra: "
"Cannot asign IO res\n");
continue;
}
dev->res[bar_index].flags = IORESOURCE_IO;
dev->res[bar_index].start = addr;
dev->res[bar_index].end = addr + size -1;
pci_tegra_io_base = addr + size;
} else {
size &= ~0xF; /* Ignore the last 4 bits */
size = ~size + 1; /* Do the 1's complement */
if (flags & 0x08) {
addr = ALIGN(pci_tegra_mem_base, size);
if (addr + size > pci_tegra_mem_limit) {
pr_err("pci_tegra: "
"Cannot asign mem res\n");
continue;
}
dev->res[bar_index].flags = IORESOURCE_MEM;
dev->res[bar_index].start = addr;
dev->res[bar_index].end =
dev->res[bar_index].start + size - 1;
pci_tegra_mem_base = addr + size;
} else {
addr = ALIGN(pci_tegra_prefetch_base, size);
if (addr + size > pci_tegra_prefetch_limit) {
pr_err("pci_tegra: "
"Cannot asign prefetch res\n");
continue;
}
dev->res[bar_index].flags =
IORESOURCE_MEM | IORESOURCE_PREFETCH;
dev->res[bar_index].start = addr;
dev->res[bar_index].end = addr + size - 1;
pci_tegra_prefetch_base = addr + size;
}
}
pci_conf_write32(dev->bus, dev->devfn, bar_index * 4
+ PCI_BASE_ADDRESS_0, dev->res[bar_index].start);
/* Handle 64 bit addresses by forcing to 32 bit addresses */
if ((flags == 0x0c) || (flags==0x04)) {
bar_index++;
BUG_ON(bar_index > PCI_STD_RESOURCE_END);
pci_conf_write32(dev->bus, dev->devfn, bar_index * 4
+ PCI_BASE_ADDRESS_0, 0);
}
}
reg = 0;
reg |= PCI_COMMAND_IO;
reg |= PCI_COMMAND_MEMORY;
reg |= PCI_COMMAND_MASTER;
reg |= PCI_COMMAND_SERR;
pci_conf_write16(dev->bus, dev->devfn, PCI_COMMAND, reg);
pci_conf_write8(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, INT_PCIE_INTR);
pci_conf_write8(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 0xa);
}
static void pci_tegra_print_device_tree(struct pci_tegra_device *dev)
{
u32 i;
if (!dev)
return;
if (dev->sub_bus)
pr_err("PCIe bridge/Root port\n");
else
pr_err("PCIe device\n");
pr_err(" Vendor/Device = 0x%x bus = %d sec bus %d sub bus %d\n",
dev->id, dev->bus, dev->sec_bus, dev->sub_bus);
if (dev->disabled) {
pr_err(" Slot disabled\n");
} else {
for (i=0; i<= PCI_STD_RESOURCE_END; i++) {
/* Skip printing the empty ones */
if (!dev->res[i].start)
continue;
pr_err(" bar(%d) \n", i);
pr_err(" start = 0x%x\n", dev->res[i].start);
pr_err(" end = 0x%x\n", dev->res[i].end);
pr_err(" flags = 0x%lx\n", dev->res[i].flags);
}
}
if (dev->child != NULL)
pci_tegra_print_device_tree(dev->child);
if (dev->next != NULL)
pci_tegra_print_device_tree(dev->next);
}
static void pci_tegra_allocate_resources(struct pci_tegra_device *dev)
{
/* Employing a depth first search for resource allocation. */
if (!dev)
return;
if (dev->sub_bus) {
dev->res[PCI_BRIDGE_IO_RES].flags = IORESOURCE_IO;
dev->res[PCI_BRIDGE_IO_RES].start = pci_tegra_io_base;
dev->res[PCI_BRIDGE_PREFETCH_RES].flags =
IORESOURCE_MEM | IORESOURCE_PREFETCH;
dev->res[PCI_BRIDGE_PREFETCH_RES].start =
pci_tegra_prefetch_base;
dev->res[PCI_BRIDGE_MEM_RES].flags = IORESOURCE_MEM;
dev->res[PCI_BRIDGE_MEM_RES].start = pci_tegra_mem_base;
}
if (dev->child)
pci_tegra_allocate_resources(dev->child);
if (dev->next)
pci_tegra_allocate_resources(dev->next);
if (dev->sub_bus)
pci_tegra_setup_pci_bridge(dev);
else {
pci_tegra_setup_pci_device(dev);
pci_tegra_io_base = ALIGN(pci_tegra_io_base, 0x1000);
pci_tegra_mem_base = ALIGN(pci_tegra_mem_base, 0x1000000);
pci_tegra_prefetch_base =
ALIGN(pci_tegra_prefetch_base, 0x1000000);
}
}
void pci_tegra_enumerate(void)
{
u32 reg;
/* Disable all execptions */
pci_tegra_afi_writel(0, AFI_FPCI_ERROR_MASKS_0);
/* Set the base and limits for the resources */
/* Starting the IO offset from non-zero value as linux equating a value
* of 0 as unallocated resoruce and bailing out!
*/
pci_tegra_io_base = TEGRA_PCIE_BASE + PCIE_DOWNSTREAM_IO_OFFSET + 16;
pci_tegra_io_limt = pci_tegra_io_base + PCIE_DOWNSTREAM_IO_SIZE;
pci_tegra_mem_base = FPCI_NON_PREFETCH_MEMORY_OFFSET;
pci_tegra_mem_limit = FPCI_NON_PREFETCH_MEMORY_OFFSET
+ PCIE_NON_PREFETCH_MEMORY_SIZE;
pci_tegra_prefetch_base = FPCI_PREFETCH_MEMORY_OFFSET;
pci_tegra_prefetch_limit = FPCI_PREFETCH_MEMORY_OFFSET
+ PCIE_PREFETCH_MEMORY_SIZE;
/* Enumerate only if the Link is UP. */
reg = pci_tegra_rp_readl(NV_PROJ__PCIE2_RP_VEND_XP, 0);
if (NVPCIE_DRF_VAL(RP, VEND_XP, DL_UP, reg) == 1)
pci_tegra_enumerate_root_port(0);
reg = pci_tegra_rp_readl(NV_PROJ__PCIE2_RP_VEND_XP, 1);
if (NVPCIE_DRF_VAL(RP, VEND_XP, DL_UP, reg) == 1)
pci_tegra_enumerate_root_port(1);
pci_tegra_print_device_tree(pci_root);
}
|