small tidy up. keep acpi open for the scope of the class, since we will need it again...
[AROS.git] / arch / all-pc / hidds / pcipc / pciconf2.c
blob15128e03ec53d4ffcfcce520c4d216c2a6f70658
1 /*
2 Copyright © 2004-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: PCI configuration mechanism 2 access functions
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include <asm/io.h>
11 #include <proto/exec.h>
13 #include "pci.h"
15 #ifdef LEGACY_SUPPORT
17 #define CFG2ADD(dev,reg) \
18 (0xc000 | ((dev)<<8) | ((reg)&~3))
20 static ULONG ReadConfig2Long(UBYTE bus, UBYTE dev, UBYTE sub, UWORD reg)
22 ULONG temp;
24 if (dev < 16)
26 Disable();
28 outb(0xf0|(sub<<1),PCI_AddressPort);
29 outb(bus,PCI_ForwardPort);
30 temp=inl(CFG2ADD(dev, reg));
31 outb(0,PCI_AddressPort);
33 Enable();
34 return temp;
36 else
37 return 0xffffffff;
40 static void WriteConfig2Long(UBYTE bus, UBYTE dev, UBYTE sub, UWORD reg, ULONG val)
42 if (dev < 16)
44 Disable();
45 outb(0xf0|(sub<<1),PCI_CSEPort);
46 outb(bus,PCI_ForwardPort);
47 outl(val,CFG2ADD(dev, reg));
48 outb(0,PCI_AddressPort);
49 Enable();
53 static inline BOOL SanityCheck(struct pcipc_staticdata *psd)
55 UWORD temp;
57 /* Check if the bus 0 is not empty */
58 temp = ReadConfigWord(psd, 0, 0, 0, PCICS_PRODUCT);
59 if ((temp != 0x0000) && (temp != 0xFFFF))
60 return TRUE;
62 D(bug("[PCI.PC] Sanity check failed\n"));
63 return FALSE;
66 static BOOL PCIPC_ProbeMech1Conf(struct pcipc_staticdata *psd)
68 ULONG temp = inl(PCI_AddressPort);
69 ULONG val;
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"));
79 if (SanityCheck(psd))
81 /* Successfully detected exit */
82 return TRUE;
86 return FALSE;
89 void PCIPC_ProbeConfMech(struct pcipc_staticdata *psd)
92 * All newer boards support atleast mechanism 1.
93 * We probe for it first, because on some machines (e.g. MacMini), PCI_MechSelect is
94 * used by the chipset as a reset register (and perhaps some other proprietary control).
95 * Writing 0x01 to it makes the machine's cold reboot mechanism stop working.
97 if (PCIPC_ProbeMech1Conf(psd))
98 return;
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);
105 if (PCIPC_ProbeMech1Conf(psd))
106 return;
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))
122 /* Confirmed */
123 return;
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;
138 #endif