1
2
3
4
5
6
7
8
9
10#include <common.h>
11#ifdef CONFIG_PCI
12#include <pci.h>
13
14#include "../../Marvell/include/pci.h"
15
16#undef DEBUG
17#undef IDE_SET_NATIVE_MODE
18static unsigned int local_buses[] = { 0, 0 };
19
20static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
21 {0, 0, 0, 0, 0, 0, 0, 27, 27, [9 ... PCI_MAX_DEVICES - 1] = 0 },
22 {0, 0, 0, 0, 0, 0, 0, 29, 29, [9 ... PCI_MAX_DEVICES - 1] = 0 },
23};
24
25#ifdef CONFIG_USE_CPCIDVI
26typedef struct {
27 unsigned int base;
28 unsigned int init;
29} GT_CPCIDVI_ROM_T;
30
31static GT_CPCIDVI_ROM_T gt_cpcidvi_rom = {0, 0};
32#endif
33
34#ifdef DEBUG
35static const unsigned int pci_bus_list[] = { PCI_0_MODE, PCI_1_MODE };
36static void gt_pci_bus_mode_display (PCI_HOST host)
37{
38 unsigned int mode;
39
40
41 mode = (GTREGREAD (pci_bus_list[host]) & (BIT4 | BIT5)) >> 4;
42 switch (mode) {
43 case 0:
44 printf ("PCI %d bus mode: Conventional PCI\n", host);
45 break;
46 case 1:
47 printf ("PCI %d bus mode: 66 MHz PCIX\n", host);
48 break;
49 case 2:
50 printf ("PCI %d bus mode: 100 MHz PCIX\n", host);
51 break;
52 case 3:
53 printf ("PCI %d bus mode: 133 MHz PCIX\n", host);
54 break;
55 default:
56 printf ("Unknown BUS %d\n", mode);
57 }
58}
59#endif
60
61static const unsigned int pci_p2p_configuration_reg[] = {
62 PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION
63};
64
65static const unsigned int pci_configuration_address[] = {
66 PCI_0CONFIGURATION_ADDRESS, PCI_1CONFIGURATION_ADDRESS
67};
68
69static const unsigned int pci_configuration_data[] = {
70 PCI_0CONFIGURATION_DATA_VIRTUAL_REGISTER,
71 PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER
72};
73
74static const unsigned int pci_error_cause_reg[] = {
75 PCI_0ERROR_CAUSE, PCI_1ERROR_CAUSE
76};
77
78static const unsigned int pci_arbiter_control[] = {
79 PCI_0ARBITER_CONTROL, PCI_1ARBITER_CONTROL
80};
81
82static const unsigned int pci_address_space_en[] = {
83 PCI_0_BASE_ADDR_REG_ENABLE, PCI_1_BASE_ADDR_REG_ENABLE
84};
85
86static const unsigned int pci_snoop_control_base_0_low[] = {
87 PCI_0SNOOP_CONTROL_BASE_0_LOW, PCI_1SNOOP_CONTROL_BASE_0_LOW
88};
89static const unsigned int pci_snoop_control_top_0[] = {
90 PCI_0SNOOP_CONTROL_TOP_0, PCI_1SNOOP_CONTROL_TOP_0
91};
92
93static const unsigned int pci_access_control_base_0_low[] = {
94 PCI_0ACCESS_CONTROL_BASE_0_LOW, PCI_1ACCESS_CONTROL_BASE_0_LOW
95};
96static const unsigned int pci_access_control_top_0[] = {
97 PCI_0ACCESS_CONTROL_TOP_0, PCI_1ACCESS_CONTROL_TOP_0
98};
99
100static const unsigned int pci_scs_bank_size[2][4] = {
101 {PCI_0SCS_0_BANK_SIZE, PCI_0SCS_1_BANK_SIZE,
102 PCI_0SCS_2_BANK_SIZE, PCI_0SCS_3_BANK_SIZE},
103 {PCI_1SCS_0_BANK_SIZE, PCI_1SCS_1_BANK_SIZE,
104 PCI_1SCS_2_BANK_SIZE, PCI_1SCS_3_BANK_SIZE}
105};
106
107static const unsigned int pci_p2p_configuration[] = {
108 PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION
109};
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130void pciWriteConfigReg (PCI_HOST host, unsigned int regOffset,
131 unsigned int pciDevNum, unsigned int data)
132{
133 volatile unsigned int DataForAddrReg;
134 unsigned int functionNum;
135 unsigned int busNum = 0;
136 unsigned int addr;
137
138 if (pciDevNum > 32)
139 return;
140 if (pciDevNum == SELF) {
141 pciDevNum =
142 (GTREGREAD (pci_p2p_configuration_reg[host]) >> 24) &
143 0x1f;
144 busNum = GTREGREAD (pci_p2p_configuration_reg[host]) &
145 0xff0000;
146 }
147 functionNum = regOffset & 0x00000700;
148 pciDevNum = pciDevNum << 11;
149 regOffset = regOffset & 0xfc;
150 DataForAddrReg =
151 (regOffset | pciDevNum | functionNum | busNum) | BIT31;
152 GT_REG_WRITE (pci_configuration_address[host], DataForAddrReg);
153 GT_REG_READ (pci_configuration_address[host], &addr);
154 if (addr != DataForAddrReg)
155 return;
156 GT_REG_WRITE (pci_configuration_data[host], data);
157}
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177unsigned int pciReadConfigReg (PCI_HOST host, unsigned int regOffset,
178 unsigned int pciDevNum)
179{
180 volatile unsigned int DataForAddrReg;
181 unsigned int data;
182 unsigned int functionNum;
183 unsigned int busNum = 0;
184
185 if (pciDevNum > 32)
186 return 0xffffffff;
187 if (pciDevNum == SELF) {
188 pciDevNum =
189 (GTREGREAD (pci_p2p_configuration_reg[host]) >> 24) &
190 0x1f;
191 busNum = GTREGREAD (pci_p2p_configuration_reg[host]) &
192 0xff0000;
193 }
194 functionNum = regOffset & 0x00000700;
195 pciDevNum = pciDevNum << 11;
196 regOffset = regOffset & 0xfc;
197 DataForAddrReg =
198 (regOffset | pciDevNum | functionNum | busNum) | BIT31;
199 GT_REG_WRITE (pci_configuration_address[host], DataForAddrReg);
200 GT_REG_READ (pci_configuration_address[host], &data);
201 if (data != DataForAddrReg)
202 return 0xffffffff;
203 GT_REG_READ (pci_configuration_data[host], &data);
204 return data;
205}
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229void pciOverBridgeWriteConfigReg (PCI_HOST host,
230 unsigned int regOffset,
231 unsigned int pciDevNum,
232 unsigned int busNum, unsigned int data)
233{
234 unsigned int DataForReg;
235 unsigned int functionNum;
236
237 functionNum = regOffset & 0x00000700;
238 pciDevNum = pciDevNum << 11;
239 regOffset = regOffset & 0xff;
240 busNum = busNum << 16;
241 if (pciDevNum == SELF) {
242 DataForReg = (regOffset | pciDevNum | functionNum) | BIT0;
243 } else {
244 DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
245 BIT31 | BIT0;
246 }
247 GT_REG_WRITE (pci_configuration_address[host], DataForReg);
248 GT_REG_WRITE (pci_configuration_data[host], data);
249}
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273unsigned int pciOverBridgeReadConfigReg (PCI_HOST host,
274 unsigned int regOffset,
275 unsigned int pciDevNum,
276 unsigned int busNum)
277{
278 unsigned int DataForReg;
279 unsigned int data;
280 unsigned int functionNum;
281
282 functionNum = regOffset & 0x00000700;
283 pciDevNum = pciDevNum << 11;
284 regOffset = regOffset & 0xff;
285 busNum = busNum << 16;
286 if (pciDevNum == SELF) {
287 DataForReg = (regOffset | pciDevNum | functionNum) | BIT31;
288 } else {
289
290 DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
291 BIT0 | BIT31;
292 }
293 GT_REG_WRITE (pci_configuration_address[host], DataForReg);
294 GT_REG_READ (pci_configuration_data[host], &data);
295 return data;
296}
297
298
299
300
301
302
303
304
305
306static unsigned int pciGetRegOffset (PCI_HOST host, PCI_REGION region)
307{
308 switch (host) {
309 case PCI_HOST0:
310 switch (region) {
311 case PCI_IO:
312 return PCI_0I_O_LOW_DECODE_ADDRESS;
313 case PCI_REGION0:
314 return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
315 case PCI_REGION1:
316 return PCI_0MEMORY1_LOW_DECODE_ADDRESS;
317 case PCI_REGION2:
318 return PCI_0MEMORY2_LOW_DECODE_ADDRESS;
319 case PCI_REGION3:
320 return PCI_0MEMORY3_LOW_DECODE_ADDRESS;
321 }
322 case PCI_HOST1:
323 switch (region) {
324 case PCI_IO:
325 return PCI_1I_O_LOW_DECODE_ADDRESS;
326 case PCI_REGION0:
327 return PCI_1MEMORY0_LOW_DECODE_ADDRESS;
328 case PCI_REGION1:
329 return PCI_1MEMORY1_LOW_DECODE_ADDRESS;
330 case PCI_REGION2:
331 return PCI_1MEMORY2_LOW_DECODE_ADDRESS;
332 case PCI_REGION3:
333 return PCI_1MEMORY3_LOW_DECODE_ADDRESS;
334 }
335 }
336 return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
337}
338
339static unsigned int pciGetRemapOffset (PCI_HOST host, PCI_REGION region)
340{
341 switch (host) {
342 case PCI_HOST0:
343 switch (region) {
344 case PCI_IO:
345 return PCI_0I_O_ADDRESS_REMAP;
346 case PCI_REGION0:
347 return PCI_0MEMORY0_ADDRESS_REMAP;
348 case PCI_REGION1:
349 return PCI_0MEMORY1_ADDRESS_REMAP;
350 case PCI_REGION2:
351 return PCI_0MEMORY2_ADDRESS_REMAP;
352 case PCI_REGION3:
353 return PCI_0MEMORY3_ADDRESS_REMAP;
354 }
355 case PCI_HOST1:
356 switch (region) {
357 case PCI_IO:
358 return PCI_1I_O_ADDRESS_REMAP;
359 case PCI_REGION0:
360 return PCI_1MEMORY0_ADDRESS_REMAP;
361 case PCI_REGION1:
362 return PCI_1MEMORY1_ADDRESS_REMAP;
363 case PCI_REGION2:
364 return PCI_1MEMORY2_ADDRESS_REMAP;
365 case PCI_REGION3:
366 return PCI_1MEMORY3_ADDRESS_REMAP;
367 }
368 }
369 return PCI_0MEMORY0_ADDRESS_REMAP;
370}
371
372
373
374
375
376
377
378
379
380
381unsigned int pciGetBaseAddress (PCI_HOST host, PCI_REGION region)
382{
383 unsigned int regBase;
384 unsigned int regEnd;
385 unsigned int regOffset = pciGetRegOffset (host, region);
386
387 GT_REG_READ (regOffset, ®Base);
388 GT_REG_READ (regOffset + 8, ®End);
389
390 if (regEnd <= regBase)
391 return 0xffffffff;
392
393 regBase = regBase << 16;
394 return regBase;
395}
396
397bool pciMapSpace (PCI_HOST host, PCI_REGION region, unsigned int remapBase,
398 unsigned int bankBase, unsigned int bankLength)
399{
400 unsigned int low = 0xfff;
401 unsigned int high = 0x0;
402 unsigned int regOffset = pciGetRegOffset (host, region);
403 unsigned int remapOffset = pciGetRemapOffset (host, region);
404
405 if (bankLength != 0) {
406 low = (bankBase >> 16) & 0xffff;
407 high = ((bankBase + bankLength) >> 16) - 1;
408 }
409
410 GT_REG_WRITE (regOffset, low | (1 << 24));
411 GT_REG_WRITE (regOffset + 8, high);
412
413 if (bankLength != 0) {
414 GT_REG_WRITE (remapOffset, remapBase >> 16);
415
416
417 }
418 return true;
419}
420
421unsigned int pciGetSpaceBase (PCI_HOST host, PCI_REGION region)
422{
423 unsigned int low;
424 unsigned int regOffset = pciGetRegOffset (host, region);
425
426 GT_REG_READ (regOffset, &low);
427 return (low & 0xffff) << 16;
428}
429
430unsigned int pciGetSpaceSize (PCI_HOST host, PCI_REGION region)
431{
432 unsigned int low, high;
433 unsigned int regOffset = pciGetRegOffset (host, region);
434
435 GT_REG_READ (regOffset, &low);
436 GT_REG_READ (regOffset + 8, &high);
437 return ((high & 0xffff) + 1) << 16;
438}
439
440
441
442
443
444
445
446void gtPciEnableInternalBAR (PCI_HOST host, PCI_INTERNAL_BAR pciBAR)
447{
448 RESET_REG_BITS (pci_address_space_en[host], BIT0 << pciBAR);
449}
450
451void gtPciDisableInternalBAR (PCI_HOST host, PCI_INTERNAL_BAR pciBAR)
452{
453 SET_REG_BITS (pci_address_space_en[host], BIT0 << pciBAR);
454}
455
456
457
458
459
460
461void pciMapMemoryBank (PCI_HOST host, MEMORY_BANK bank,
462 unsigned int pciDramBase, unsigned int pciDramSize)
463{
464
465 unsigned int offset = (bank < 2) ? bank * 8 : 0x100 + (bank - 2) * 8;
466
467 pciDramBase = pciDramBase & 0xfffff000;
468 pciDramBase = pciDramBase | (pciReadConfigReg (host,
469 PCI_SCS_0_BASE_ADDRESS
470 + offset,
471 SELF) & 0x00000fff);
472 pciWriteConfigReg (host, PCI_SCS_0_BASE_ADDRESS + offset, SELF,
473 pciDramBase);
474 if (pciDramSize == 0)
475 pciDramSize++;
476 GT_REG_WRITE (pci_scs_bank_size[host][bank], pciDramSize - 1);
477 gtPciEnableInternalBAR (host, bank);
478}
479
480
481
482
483
484
485
486
487
488
489
490
491bool pciSetRegionFeatures (PCI_HOST host, PCI_ACCESS_REGIONS region,
492 unsigned int features, unsigned int baseAddress,
493 unsigned int regionLength)
494{
495 unsigned int accessLow;
496 unsigned int accessHigh;
497 unsigned int accessTop = baseAddress + regionLength;
498
499 if (regionLength == 0) {
500 pciDisableAccessRegion (host, region);
501 return true;
502 }
503
504 accessLow = (baseAddress & 0xfff00000) >> 20;
505
506
507 accessLow = accessLow | (features & 0xfffff000);
508
509 GT_REG_WRITE (pci_access_control_base_0_low[host] + 0x10 * region,
510 accessLow);
511
512 accessHigh = (accessTop & 0xfff00000) >> 20;
513
514
515 GT_REG_WRITE (pci_access_control_top_0[host] + 0x10 * region,
516 accessHigh - 1);
517 return true;
518}
519
520
521
522
523
524
525
526
527void pciDisableAccessRegion (PCI_HOST host, PCI_ACCESS_REGIONS region)
528{
529
530 GT_REG_WRITE (pci_access_control_base_0_low[host] + 0x10 * region,
531 0x01001fff);
532 GT_REG_WRITE (pci_access_control_top_0[host] + 0x10 * region, 0);
533}
534
535
536
537
538
539
540
541bool pciArbiterEnable (PCI_HOST host)
542{
543 unsigned int regData;
544
545 GT_REG_READ (pci_arbiter_control[host], ®Data);
546 GT_REG_WRITE (pci_arbiter_control[host], regData | BIT31);
547 return true;
548}
549
550
551
552
553
554
555
556bool pciArbiterDisable (PCI_HOST host)
557{
558 unsigned int regData;
559
560 GT_REG_READ (pci_arbiter_control[host], ®Data);
561 GT_REG_WRITE (pci_arbiter_control[host], regData & 0x7fffffff);
562 return true;
563}
564
565
566
567
568
569
570
571
572
573
574
575
576
577bool pciSetArbiterAgentsPriority (PCI_HOST host, PCI_AGENT_PRIO internalAgent,
578 PCI_AGENT_PRIO externalAgent0,
579 PCI_AGENT_PRIO externalAgent1,
580 PCI_AGENT_PRIO externalAgent2,
581 PCI_AGENT_PRIO externalAgent3,
582 PCI_AGENT_PRIO externalAgent4,
583 PCI_AGENT_PRIO externalAgent5)
584{
585 unsigned int regData;
586 unsigned int writeData;
587
588 GT_REG_READ (pci_arbiter_control[host], ®Data);
589 writeData = (internalAgent << 7) + (externalAgent0 << 8) +
590 (externalAgent1 << 9) + (externalAgent2 << 10) +
591 (externalAgent3 << 11) + (externalAgent4 << 12) +
592 (externalAgent5 << 13);
593 regData = (regData & 0xffffc07f) | writeData;
594 GT_REG_WRITE (pci_arbiter_control[host], regData & regData);
595 return true;
596}
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613bool pciParkingDisable (PCI_HOST host, PCI_AGENT_PARK internalAgent,
614 PCI_AGENT_PARK externalAgent0,
615 PCI_AGENT_PARK externalAgent1,
616 PCI_AGENT_PARK externalAgent2,
617 PCI_AGENT_PARK externalAgent3,
618 PCI_AGENT_PARK externalAgent4,
619 PCI_AGENT_PARK externalAgent5)
620{
621 unsigned int regData;
622 unsigned int writeData;
623
624 GT_REG_READ (pci_arbiter_control[host], ®Data);
625 writeData = (internalAgent << 14) + (externalAgent0 << 15) +
626 (externalAgent1 << 16) + (externalAgent2 << 17) +
627 (externalAgent3 << 18) + (externalAgent4 << 19) +
628 (externalAgent5 << 20);
629 regData = (regData & ~(0x7f << 14)) | writeData;
630 GT_REG_WRITE (pci_arbiter_control[host], regData);
631 return true;
632}
633
634
635
636
637
638
639
640
641
642
643bool pciEnableBrokenAgentDetection (PCI_HOST host, unsigned char brokenValue)
644{
645 unsigned int data;
646 unsigned int regData;
647
648 if (brokenValue > 0xf)
649 return false;
650 data = brokenValue << 3;
651 GT_REG_READ (pci_arbiter_control[host], ®Data);
652 regData = (regData & 0xffffff87) | data;
653 GT_REG_WRITE (pci_arbiter_control[host], regData | BIT1);
654 return true;
655}
656
657
658
659
660
661
662
663
664
665
666bool pciDisableBrokenAgentDetection (PCI_HOST host)
667{
668 unsigned int regData;
669
670 GT_REG_READ (pci_arbiter_control[host], ®Data);
671 regData = regData & 0xfffffffd;
672 GT_REG_WRITE (pci_arbiter_control[host], regData);
673 return true;
674}
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690bool pciP2PConfig (PCI_HOST host, unsigned int SecondBusLow,
691 unsigned int SecondBusHigh,
692 unsigned int busNum, unsigned int devNum)
693{
694 unsigned int regData;
695
696 regData = (SecondBusLow & 0xff) | ((SecondBusHigh & 0xff) << 8) |
697 ((busNum & 0xff) << 16) | ((devNum & 0x1f) << 24);
698 GT_REG_WRITE (pci_p2p_configuration[host], regData);
699 return true;
700}
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715bool pciSetRegionSnoopMode (PCI_HOST host, PCI_SNOOP_REGION region,
716 PCI_SNOOP_TYPE snoopType,
717 unsigned int baseAddress,
718 unsigned int regionLength)
719{
720 unsigned int snoopXbaseAddress;
721 unsigned int snoopXtopAddress;
722 unsigned int data;
723 unsigned int snoopHigh = baseAddress + regionLength;
724
725 if ((region > PCI_SNOOP_REGION3) || (snoopType > PCI_SNOOP_WB))
726 return false;
727 snoopXbaseAddress =
728 pci_snoop_control_base_0_low[host] + 0x10 * region;
729 snoopXtopAddress = pci_snoop_control_top_0[host] + 0x10 * region;
730 if (regionLength == 0) {
731 GT_REG_WRITE (snoopXbaseAddress, 0x0000ffff);
732 GT_REG_WRITE (snoopXtopAddress, 0);
733 return true;
734 }
735 baseAddress = baseAddress & 0xfff00000;
736 data = (baseAddress >> 20) | snoopType << 12;
737 GT_REG_WRITE (snoopXbaseAddress, data);
738 snoopHigh = (snoopHigh & 0xfff00000) >> 20;
739 GT_REG_WRITE (snoopXtopAddress, snoopHigh - 1);
740 return true;
741}
742
743static int gt_read_config_dword (struct pci_controller *hose,
744 pci_dev_t dev, int offset, u32 * value)
745{
746 int bus = PCI_BUS (dev);
747
748 if ((bus == local_buses[0]) || (bus == local_buses[1])) {
749 *value = pciReadConfigReg ((PCI_HOST) hose->cfg_addr, offset,
750 PCI_DEV (dev));
751 } else {
752 *value = pciOverBridgeReadConfigReg ((PCI_HOST) hose->
753 cfg_addr, offset,
754 PCI_DEV (dev), bus);
755 }
756
757 return 0;
758}
759
760static int gt_write_config_dword (struct pci_controller *hose,
761 pci_dev_t dev, int offset, u32 value)
762{
763 int bus = PCI_BUS (dev);
764
765 if ((bus == local_buses[0]) || (bus == local_buses[1])) {
766 pciWriteConfigReg ((PCI_HOST) hose->cfg_addr, offset,
767 PCI_DEV (dev), value);
768 } else {
769 pciOverBridgeWriteConfigReg ((PCI_HOST) hose->cfg_addr,
770 offset, PCI_DEV (dev), bus,
771 value);
772 }
773 return 0;
774}
775
776
777static void gt_setup_ide (struct pci_controller *hose,
778 pci_dev_t dev, struct pci_config_table *entry)
779{
780 static const int ide_bar[] = { 8, 4, 8, 4, 0, 0 };
781 u32 bar_response, bar_value;
782 int bar;
783
784 for (bar = 0; bar < 6; bar++) {
785
786 unsigned int offset =
787 (bar < 2) ? bar * 8 : 0x100 + (bar - 2) * 8;
788
789 pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + offset,
790 0x0);
791 pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + offset,
792 &bar_response);
793
794 pciauto_region_allocate (bar_response &
795 PCI_BASE_ADDRESS_SPACE_IO ? hose->
796 pci_io : hose->pci_mem, ide_bar[bar],
797 &bar_value);
798
799 pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0 + bar * 4,
800 bar_value);
801 }
802}
803
804#ifdef CONFIG_USE_CPCIDVI
805static void gt_setup_cpcidvi (struct pci_controller *hose,
806 pci_dev_t dev, struct pci_config_table *entry)
807{
808 u32 bar_value, pci_response;
809
810 pci_hose_read_config_dword (hose, dev, PCI_COMMAND, &pci_response);
811 pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0, 0xffffffff);
812 pci_hose_read_config_dword (hose, dev, PCI_BASE_ADDRESS_0, &pci_response);
813 pciauto_region_allocate (hose->pci_mem, 0x01000000, &bar_value);
814 pci_hose_write_config_dword (hose, dev, PCI_BASE_ADDRESS_0, (bar_value & 0xffffff00));
815 pci_hose_write_config_dword (hose, dev, PCI_ROM_ADDRESS, 0x0);
816 pciauto_region_allocate (hose->pci_mem, 0x40000, &bar_value);
817 pci_hose_write_config_dword (hose, dev, PCI_ROM_ADDRESS, (bar_value & 0xffffff00) | 0x01);
818 gt_cpcidvi_rom.base = bar_value & 0xffffff00;
819 gt_cpcidvi_rom.init = 1;
820}
821
822unsigned char gt_cpcidvi_in8(unsigned int offset)
823{
824 unsigned char data;
825
826 if (gt_cpcidvi_rom.init == 0) {
827 return(0);
828 }
829 data = in8((offset & 0x04) + 0x3f000 + gt_cpcidvi_rom.base);
830 return(data);
831}
832
833void gt_cpcidvi_out8(unsigned int offset, unsigned char data)
834{
835 unsigned int off;
836
837 if (gt_cpcidvi_rom.init == 0) {
838 return;
839 }
840 off = data;
841 off = ((off << 3) & 0x7f8) + (offset & 0x4) + 0x3e000 + gt_cpcidvi_rom.base;
842 in8(off);
843 return;
844}
845#endif
846
847
848
849#if 0
850static void gt_fixup_irq (struct pci_controller *hose, pci_dev_t dev)
851{
852 unsigned char pin, irq;
853
854 pci_read_config_byte (dev, PCI_INTERRUPT_PIN, &pin);
855
856 if (pin == 1) {
857 irq = pci_irq_swizzle[(PCI_HOST) hose->
858 cfg_addr][PCI_DEV (dev)];
859 if (irq)
860 pci_write_config_byte (dev, PCI_INTERRUPT_LINE, irq);
861 }
862}
863#endif
864
865struct pci_config_table gt_config_table[] = {
866#ifdef CONFIG_USE_CPCIDVI
867 {PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_69030, PCI_CLASS_DISPLAY_VGA,
868 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_cpcidvi},
869#endif
870 {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE,
871 PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_ide},
872 {}
873};
874
875struct pci_controller pci0_hose = {
876
877 config_table:gt_config_table,
878};
879
880struct pci_controller pci1_hose = {
881
882 config_table:gt_config_table,
883};
884
885void pci_init_board (void)
886{
887 unsigned int command;
888#ifdef CONFIG_PCI_PNP
889 unsigned int bar;
890#endif
891#ifdef DEBUG
892 gt_pci_bus_mode_display (PCI_HOST0);
893#endif
894#ifdef CONFIG_USE_CPCIDVI
895 gt_cpcidvi_rom.init = 0;
896 gt_cpcidvi_rom.base = 0;
897#endif
898
899 pci0_hose.config_table = gt_config_table;
900 pci1_hose.config_table = gt_config_table;
901
902#ifdef CONFIG_USE_CPCIDVI
903 gt_config_table[0].config_device = gt_setup_cpcidvi;
904#endif
905 gt_config_table[1].config_device = gt_setup_ide;
906
907 pci0_hose.first_busno = 0;
908 pci0_hose.last_busno = 0xff;
909 local_buses[0] = pci0_hose.first_busno;
910
911
912 pci_set_region (pci0_hose.regions + 0,
913 CONFIG_SYS_PCI0_0_MEM_SPACE,
914 CONFIG_SYS_PCI0_0_MEM_SPACE,
915 CONFIG_SYS_PCI0_MEM_SIZE, PCI_REGION_MEM);
916
917
918 pci_set_region (pci0_hose.regions + 1,
919 CONFIG_SYS_PCI0_IO_SPACE_PCI,
920 CONFIG_SYS_PCI0_IO_SPACE, CONFIG_SYS_PCI0_IO_SIZE, PCI_REGION_IO);
921
922 pci_set_ops (&pci0_hose,
923 pci_hose_read_config_byte_via_dword,
924 pci_hose_read_config_word_via_dword,
925 gt_read_config_dword,
926 pci_hose_write_config_byte_via_dword,
927 pci_hose_write_config_word_via_dword,
928 gt_write_config_dword);
929 pci0_hose.region_count = 2;
930
931 pci0_hose.cfg_addr = (unsigned int *) PCI_HOST0;
932
933 pci_register_hose (&pci0_hose);
934 pciArbiterDisable(PCI_HOST0);
935 pciParkingDisable (PCI_HOST0, 1, 1, 1, 1, 1, 1, 1);
936 command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF);
937 command |= PCI_COMMAND_MASTER;
938 pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command);
939 command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF);
940 command |= PCI_COMMAND_MEMORY;
941 pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command);
942
943#ifdef CONFIG_PCI_PNP
944 pciauto_config_init(&pci0_hose);
945 pciauto_region_allocate(pci0_hose.pci_io, 0x400, &bar);
946#endif
947#ifdef CONFIG_PCI_SCAN_SHOW
948 printf("PCI: Bus Dev VenId DevId Class Int\n");
949#endif
950 pci0_hose.last_busno = pci_hose_scan_bus (&pci0_hose, pci0_hose.first_busno);
951
952#ifdef DEBUG
953 gt_pci_bus_mode_display (PCI_HOST1);
954#endif
955 pci1_hose.first_busno = pci0_hose.last_busno + 1;
956 pci1_hose.last_busno = 0xff;
957 pci1_hose.current_busno = pci1_hose.first_busno;
958 local_buses[1] = pci1_hose.first_busno;
959
960
961 pci_set_region (pci1_hose.regions + 0,
962 CONFIG_SYS_PCI1_0_MEM_SPACE,
963 CONFIG_SYS_PCI1_0_MEM_SPACE,
964 CONFIG_SYS_PCI1_MEM_SIZE, PCI_REGION_MEM);
965
966
967 pci_set_region (pci1_hose.regions + 1,
968 CONFIG_SYS_PCI1_IO_SPACE_PCI,
969 CONFIG_SYS_PCI1_IO_SPACE, CONFIG_SYS_PCI1_IO_SIZE, PCI_REGION_IO);
970
971 pci_set_ops (&pci1_hose,
972 pci_hose_read_config_byte_via_dword,
973 pci_hose_read_config_word_via_dword,
974 gt_read_config_dword,
975 pci_hose_write_config_byte_via_dword,
976 pci_hose_write_config_word_via_dword,
977 gt_write_config_dword);
978
979 pci1_hose.region_count = 2;
980
981 pci1_hose.cfg_addr = (unsigned int *) PCI_HOST1;
982
983 pci_register_hose (&pci1_hose);
984
985 pciArbiterEnable (PCI_HOST1);
986 pciParkingDisable (PCI_HOST1, 1, 1, 1, 1, 1, 1, 1);
987
988 command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF);
989 command |= PCI_COMMAND_MASTER;
990 pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);
991
992#ifdef CONFIG_PCI_PNP
993 pciauto_config_init(&pci1_hose);
994 pciauto_region_allocate(pci1_hose.pci_io, 0x400, &bar);
995#endif
996 pci1_hose.last_busno = pci_hose_scan_bus (&pci1_hose, pci1_hose.first_busno);
997
998 command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF);
999 command |= PCI_COMMAND_MEMORY;
1000 pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);
1001
1002}
1003#endif
1004