1c6a29a37772360c28cbf73ee2dc2b20329f16f9
[reactos.git] / reactos / hal / halx86 / xbox / pci_xbox.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: hal/halx86/xbox/pci_xbox.c
6 * PURPOSE: Xbox specific handling of PCI cards
7 * PROGRAMMER: Ge van Geldorp (gvg@reactos.com)
8 * UPDATE HISTORY:
9 * 2004/12/04: Created
10 *
11 * Trying to get PCI config data from devices 0:0:1 and 0:0:2 will completely
12 * hang the Xbox. Also, the device number doesn't seem to be decoded for the
13 * video card, so it appears to be present on 1:0:0 - 1:31:0.
14 * We hack around these problems by indicating "device not present" for devices
15 * 0:0:1, 0:0:2, 1:1:0, 1:2:0, 1:3:0, ...., 1:31:0
16 */
17
18 /* INCLUDES *****************************************************************/
19
20 #define NDEBUG
21
22 #include <ddk/ntddk.h>
23 #include <hal.h>
24 #include <bus.h>
25 #include "halxbox.h"
26
27 #include <internal/debug.h>
28 #include <debug.h>
29
30 /* VARIABLES ***************************************************************/
31
32 static ULONG (STDCALL *GenericGetPciData)(PBUS_HANDLER BusHandler,
33 ULONG BusNumber,
34 ULONG SlotNumber,
35 PVOID Buffer,
36 ULONG Offset,
37 ULONG Length);
38 static ULONG (STDCALL *GenericSetPciData)(PBUS_HANDLER BusHandler,
39 ULONG BusNumber,
40 ULONG SlotNumber,
41 PVOID Buffer,
42 ULONG Offset,
43 ULONG Length);
44
45 /* FUNCTIONS ***************************************************************/
46
47 static ULONG STDCALL
48 HalpXboxGetPciData(PBUS_HANDLER BusHandler,
49 ULONG BusNumber,
50 ULONG SlotNumber,
51 PVOID Buffer,
52 ULONG Offset,
53 ULONG Length)
54 {
55 DPRINT("HalpXboxGetPciData() called.\n");
56 DPRINT(" BusNumber %lu\n", BusNumber);
57 DPRINT(" SlotNumber %lu\n", SlotNumber);
58 DPRINT(" Offset 0x%lx\n", Offset);
59 DPRINT(" Length 0x%lx\n", Length);
60
61 if ((0 == BusNumber && 0 == (SlotNumber & 0x1f) &&
62 (1 == ((SlotNumber >> 5) & 0x07) || 2 == ((SlotNumber >> 5) & 0x07))) ||
63 (1 == BusNumber && 0 != (SlotNumber & 0x1f)))
64 {
65 DPRINT("Blacklisted PCI slot\n");
66 if (0 == Offset && 2 <= Length)
67 {
68 *(PUSHORT)Buffer = PCI_INVALID_VENDORID;
69 return 2;
70 }
71 return 0;
72 }
73
74 return GenericGetPciData(BusHandler, BusNumber, SlotNumber, Buffer, Offset, Length);
75 }
76
77 static ULONG STDCALL
78 HalpXboxSetPciData(PBUS_HANDLER BusHandler,
79 ULONG BusNumber,
80 ULONG SlotNumber,
81 PVOID Buffer,
82 ULONG Offset,
83 ULONG Length)
84 {
85 DPRINT("HalpXboxSetPciData() called.\n");
86 DPRINT(" BusNumber %lu\n", BusNumber);
87 DPRINT(" SlotNumber %lu\n", SlotNumber);
88 DPRINT(" Offset 0x%lx\n", Offset);
89 DPRINT(" Length 0x%lx\n", Length);
90
91 if ((0 == BusNumber && 0 == (SlotNumber & 0x1f) &&
92 (1 == ((SlotNumber >> 5) & 0x07) || 2 == ((SlotNumber >> 5) & 0x07))) ||
93 (1 == BusNumber && 0 != (SlotNumber & 0x1f)))
94 {
95 DPRINT1("Trying to set data on blacklisted PCI slot\n");
96 return 0;
97 }
98
99 return GenericSetPciData(BusHandler, BusNumber, SlotNumber, Buffer, Offset, Length);
100 }
101
102 void
103 HalpXboxInitPciBus(ULONG BusNumber, PBUS_HANDLER BusHandler)
104 {
105 if (0 == BusNumber || 1 == BusNumber)
106 {
107 GenericGetPciData = BusHandler->GetBusData;
108 BusHandler->GetBusData = HalpXboxGetPciData;
109 GenericSetPciData = BusHandler->SetBusData;
110 BusHandler->SetBusData = HalpXboxSetPciData;
111 }
112 }
113
114 /* EOF */