3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halx86/generic/bus/sysbus.c
6 * PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 /* PRIVATE FUNCTIONS **********************************************************/
21 HalpTranslateSystemBusAddress(IN PBUS_HANDLER BusHandler
,
22 IN PBUS_HANDLER RootHandler
,
23 IN PHYSICAL_ADDRESS BusAddress
,
24 IN OUT PULONG AddressSpace
,
25 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
27 PSUPPORTED_RANGE Range
= NULL
;
29 /* Check what kind of address space this is */
30 switch (*AddressSpace
)
35 /* Loop all prefetech memory */
36 for (Range
= &BusHandler
->BusAddresses
->PrefetchMemory
;
40 /* Check if it's in a valid range */
41 if ((BusAddress
.QuadPart
>= Range
->Base
) &&
42 (BusAddress
.QuadPart
<= Range
->Limit
))
49 /* Check if we haven't found anything yet */
52 /* Loop all bus memory */
53 for (Range
= &BusHandler
->BusAddresses
->Memory
;
57 /* Check if it's in a valid range */
58 if ((BusAddress
.QuadPart
>= Range
->Base
) &&
59 (BusAddress
.QuadPart
<= Range
->Limit
))
73 /* Loop all bus I/O memory */
74 for (Range
= &BusHandler
->BusAddresses
->IO
;
78 /* Check if it's in a valid range */
79 if ((BusAddress
.QuadPart
>= Range
->Base
) &&
80 (BusAddress
.QuadPart
<= Range
->Limit
))
91 /* Check if we found a range */
94 /* Do the translation and return the kind of address space this is */
95 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
+ Range
->SystemBase
;
96 if ((TranslatedAddress
->QuadPart
!= BusAddress
.QuadPart
) ||
97 (*AddressSpace
!= Range
->SystemAddressSpace
))
99 /* Different than what the old HAL would do */
100 DPRINT1("Translation of %I64x is %I64x %s\n",
101 BusAddress
.QuadPart
, TranslatedAddress
->QuadPart
,
102 Range
->SystemAddressSpace
? "In I/O Space" : "In RAM");
104 *AddressSpace
= Range
->SystemAddressSpace
;
109 DPRINT1("Translation of %I64x failed!\n", BusAddress
.QuadPart
);
115 HalpGetRootInterruptVector(IN ULONG BusInterruptLevel
,
116 IN ULONG BusInterruptVector
,
118 OUT PKAFFINITY Affinity
)
122 /* Validate the IRQ */
123 if (BusInterruptLevel
> 23)
126 DPRINT1("IRQ %lx is too high!\n", BusInterruptLevel
);
130 /* Get the system vector */
131 SystemVector
= HalpIrqToVector((UCHAR
)BusInterruptLevel
);
133 /* Return the IRQL and affinity */
134 *Irql
= HalpVectorToIrql(SystemVector
);
135 *Affinity
= HalpDefaultInterruptAffinity
;
136 ASSERT(HalpDefaultInterruptAffinity
);
138 /* Return the vector */
144 HalpGetSystemInterruptVector(IN PBUS_HANDLER BusHandler
,
145 IN PBUS_HANDLER RootHandler
,
146 IN ULONG BusInterruptLevel
,
147 IN ULONG BusInterruptVector
,
149 OUT PKAFFINITY Affinity
)
153 /* Get the root vector */
154 Vector
= HalpGetRootInterruptVector(BusInterruptLevel
,
159 /* Check if the vector is owned by the HAL and fail if it is */
160 if (HalpIDTUsageFlags
[Vector
].Flags
& IDT_REGISTERED
) DPRINT1("Vector %lx is ALREADY IN USE!\n", Vector
);
161 return (HalpIDTUsageFlags
[Vector
].Flags
& IDT_REGISTERED
) ? 0 : Vector
;