Kernel - More work on ARM port
[tpg/acess2.git] / Kernel / arch / x86 / pci.c
1 /*\r
2  * Acess2\r
3  * arch/x86/pci.h - x86 PCI Bus Access\r
4  */\r
5 #define DEBUG   0\r
6 #include <acess.h>\r
7 \r
8 // === PROTOTYPES ===\r
9 Uint32  PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
10 void    PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data);\r
11 Uint16  PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
12 Uint8   PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
13 \r
14 // === CODE ===\r
15 Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
16 {\r
17         Uint32  address;\r
18         Uint32  data;\r
19         \r
20         bus &= 0xFF;    // 8 Bits\r
21         dev &= 0x1F;    // 5 Bits\r
22         func &= 0x7;    // 3 Bits\r
23         offset &= 0xFF; // 8 Bits\r
24         \r
25         address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
26         outd(0xCF8, address);\r
27         \r
28         data = ind(0xCFC);\r
29         //Debug("PCI(0x%x) = 0x%08x", address, data);\r
30         return data;\r
31 }\r
32 void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data)\r
33 {\r
34         Uint32  address;\r
35         \r
36         bus &= 0xFF;    // 8 Bits\r
37         dev &= 0x1F;    // 5 Bits\r
38         func &= 0x7;    // 3 Bits\r
39         offset &= 0xFF; // 8 Bits\r
40         \r
41         address = 0x80000000 | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC);\r
42         outd(0xCF8, address);\r
43         outd(0xCFC, data);\r
44 }\r
45 Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
46 {\r
47         Uint32  data = PCI_CfgReadDWord(bus, dev, func, offset);\r
48         \r
49         data >>= (offset&2)*8;  // Allow Access to Upper Word\r
50         \r
51         return (Uint16)data;\r
52 }\r
53 \r
54 Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset)\r
55 {\r
56         Uint32  data = PCI_CfgReadDWord(bus, dev, func, offset);\r
57         \r
58         data >>= (offset&3)*8;  //Allow Access to Upper Word\r
59         return (Uint8)data;\r
60 }\r
61 \r

UCC git Repository :: git.ucc.asn.au