2 Copyright © 2004-2016, The AROS Development Team. All rights reserved.
5 Desc: PCI configuration mechanism 2 access functions
9 #include <aros/debug.h>
11 #include <proto/exec.h>
17 #define CFG2ADD(dev,reg) \
18 (0xc000 | ((dev)<<8) | ((reg)&~3))
20 static ULONG
ReadConfig2Long(UBYTE bus
, UBYTE dev
, UBYTE sub
, UWORD reg
)
28 outb(0xf0|(sub
<<1),PCI_AddressPort
);
29 outb(bus
,PCI_ForwardPort
);
30 temp
=inl(CFG2ADD(dev
, reg
));
31 outb(0,PCI_AddressPort
);
40 static void WriteConfig2Long(UBYTE bus
, UBYTE dev
, UBYTE sub
, UWORD reg
, ULONG val
)
45 outb(0xf0|(sub
<<1),PCI_CSEPort
);
46 outb(bus
,PCI_ForwardPort
);
47 outl(val
,CFG2ADD(dev
, reg
));
48 outb(0,PCI_AddressPort
);
53 static inline BOOL
SanityCheck(struct pci_staticdata
*psd
)
57 /* Check if the bus 0 is not empty */
58 temp
= ReadConfigWord(psd
, 0, 0, 0, PCICS_PRODUCT
);
59 if ((temp
!= 0x0000) && (temp
!= 0xFFFF))
62 D(bug("[PCI.PC] Sanity check failed\n"));
66 static BOOL
ProbeMech1(struct pci_staticdata
*psd
)
68 ULONG temp
= inl(PCI_AddressPort
);
71 outl(0x80000000, PCI_AddressPort
);
72 val
= inl(PCI_AddressPort
);
73 outl(temp
, PCI_AddressPort
);
75 if (val
== 0x80000000)
77 D(bug("[PCI.PC] Configuration mechanism 1 detected\n"));
81 /* Successfully detected exit */
89 void ProbePCI(struct pci_staticdata
*psd
)
92 * All new board support only mechanism 1. So we probe for it first.
93 * We do it because on some machines (MacMini) PCI_MechSelect is
94 * used by chipset as a reset register (and perhaps some other proprietary control).
95 * Writing 0x01 to it makes machine cold reboot not working.
101 * There's no Mechanism 1.
102 * Perhaps it's Intel Neptune or alike board. We can try to switch it to Mech1.
104 outb(0x01, PCI_MechSelect
);
108 /* Completely no support. Try mechanism 2. */
109 outb(0x00, PCI_MechSelect
);
110 outb(0x00, PCI_CSEPort
);
111 outb(0x00, PCI_ForwardPort
);
113 if ((inb(PCI_CSEPort
) == 0x00) && (inb(PCI_ForwardPort
) == 0x00))
115 D(bug("[PCI.PC] configuration mechanism 2 detected\n"));
117 psd
->ReadConfigLong
= ReadConfig2Long
;
118 psd
->WriteConfigLong
= WriteConfig2Long
;
120 if (SanityCheck(psd
))
128 * Newer systems may have empty bus 0. In this case SanityCheck() will fail. We
129 * assume configuration type 1 for such systems.
130 * Probably SanityCheck() should be revised or removed at all.
132 D(bug("[PCI.PC] Failing back to configuration mechanism 1\n"));
134 psd
->ReadConfigLong
= ReadConfig1Long
;
135 psd
->WriteConfigLong
= WriteConfig1Long
;