badbe5381bb5ca3f9f8f06be6e5d139c79e1bf29
[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 #include <ddk/ntddk.h>
21 #include <hal.h>
22 #include <bus.h>
23 #include "halxbox.h"
24
25 #include <internal/debug.h>
26 #define NDEBUG
27 #include <debug.h>
28
29 /* VARIABLES ***************************************************************/
30
31 static ULONG (STDCALL *GenericGetPciData)(PBUS_HANDLER BusHandler,
32 ULONG BusNumber,
33 ULONG SlotNumber,
34 PVOID Buffer,
35 ULONG Offset,
36 ULONG Length);
37 static ULONG (STDCALL *GenericSetPciData)(PBUS_HANDLER BusHandler,
38 ULONG BusNumber,
39 ULONG SlotNumber,
40 PVOID Buffer,
41 ULONG Offset,
42 ULONG Length);
43
44 /* FUNCTIONS ***************************************************************/
45
46 static ULONG STDCALL
47 HalpXboxGetPciData(PBUS_HANDLER BusHandler,
48 ULONG BusNumber,
49 ULONG SlotNumber,
50 PVOID Buffer,
51 ULONG Offset,
52 ULONG Length)
53 {
54 DPRINT("HalpXboxGetPciData() called.\n");
55 DPRINT(" BusNumber %lu\n", BusNumber);
56 DPRINT(" SlotNumber %lu\n", SlotNumber);
57 DPRINT(" Offset 0x%lx\n", Offset);
58 DPRINT(" Length 0x%lx\n", Length);
59
60 if ((0 == BusNumber && 0 == (SlotNumber & 0x1f) &&
61 (1 == ((SlotNumber >> 5) & 0x07) || 2 == ((SlotNumber >> 5) & 0x07))) ||
62 (1 == BusNumber && 0 != (SlotNumber & 0x1f)))
63 {
64 DPRINT("Blacklisted PCI slot\n");
65 if (0 == Offset && 2 <= Length)
66 {
67 *(PUSHORT)Buffer = PCI_INVALID_VENDORID;
68 return 2;
69 }
70 return 0;
71 }
72
73 return GenericGetPciData(BusHandler, BusNumber, SlotNumber, Buffer, Offset, Length);
74 }
75
76 static ULONG STDCALL
77 HalpXboxSetPciData(PBUS_HANDLER BusHandler,
78 ULONG BusNumber,
79 ULONG SlotNumber,
80 PVOID Buffer,
81 ULONG Offset,
82 ULONG Length)
83 {
84 DPRINT("HalpXboxSetPciData() called.\n");
85 DPRINT(" BusNumber %lu\n", BusNumber);
86 DPRINT(" SlotNumber %lu\n", SlotNumber);
87 DPRINT(" Offset 0x%lx\n", Offset);
88 DPRINT(" Length 0x%lx\n", Length);
89
90 if ((0 == BusNumber && 0 == (SlotNumber & 0x1f) &&
91 (1 == ((SlotNumber >> 5) & 0x07) || 2 == ((SlotNumber >> 5) & 0x07))) ||
92 (1 == BusNumber && 0 != (SlotNumber & 0x1f)))
93 {
94 DPRINT1("Trying to set data on blacklisted PCI slot\n");
95 return 0;
96 }
97
98 return GenericSetPciData(BusHandler, BusNumber, SlotNumber, Buffer, Offset, Length);
99 }
100
101 void
102 HalpXboxInitPciBus(ULONG BusNumber, PBUS_HANDLER BusHandler)
103 {
104 if (0 == BusNumber || 1 == BusNumber)
105 {
106 GenericGetPciData = BusHandler->GetBusData;
107 BusHandler->GetBusData = HalpXboxGetPciData;
108 GenericSetPciData = BusHandler->SetBusData;
109 BusHandler->SetBusData = HalpXboxSetPciData;
110 }
111 }
112
113 /* EOF */