[FREELDR]: VaToPa/PaToVa are assuming all architectures have VA at PA | KSEG0_BASE...
[reactos.git] / reactos / boot / freeldr / freeldr / windows / conversion.c
1 /*
2 * PROJECT: EFI Windows Loader
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: freeldr/winldr/conversion.c
5 * PURPOSE: Physical <-> Virtual addressing mode conversions
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
7 */
8
9 /* INCLUDES ***************************************************************/
10
11 #include <freeldr.h>
12
13 //#include <ndk/ldrtypes.h>
14 #include <debug.h>
15
16 /* FUNCTIONS **************************************************************/
17
18 #ifndef _ZOOM2_
19 /* Arch-specific addresses translation implementation */
20 PVOID
21 VaToPa(PVOID Va)
22 {
23 return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);
24 }
25
26 PVOID
27 PaToVa(PVOID Pa)
28 {
29 return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);
30 }
31 #else
32 PVOID
33 VaToPa(PVOID Va)
34 {
35 return Va;
36 }
37
38 PVOID
39 PaToVa(PVOID Pa)
40 {
41 return Pa;
42 }
43 #endif
44
45 VOID
46 List_PaToVa(LIST_ENTRY *ListEntry)
47 {
48 LIST_ENTRY *ListHead = ListEntry;
49 LIST_ENTRY *Next = ListEntry->Flink;
50 LIST_ENTRY *NextPA;
51
52 //Print(L"\n\nList_Entry: %X, First Next: %X\n", ListEntry, Next);
53 //
54 // Walk through the whole list
55 //
56 if (Next != NULL)
57 {
58 while (Next != PaToVa(ListHead))
59 {
60 NextPA = VaToPa(Next);
61 //Print(L"Current: %X, Flink: %X, Blink: %X\n", Next, NextPA->Flink, NextPA->Blink);
62
63 NextPA->Flink = PaToVa((PVOID)NextPA->Flink);
64 NextPA->Blink = PaToVa((PVOID)NextPA->Blink);
65
66 //Print(L"After converting Flink: %X, Blink: %X\n", NextPA->Flink, NextPA->Blink);
67
68 Next = NextPA->Flink;
69 }
70
71 //
72 // Finally convert first Flink/Blink
73 //
74 ListEntry->Flink = PaToVa((PVOID)ListEntry->Flink);
75 if (ListEntry->Blink)
76 ListEntry->Blink = PaToVa((PVOID)ListEntry->Blink);
77 }
78 }
79
80 // This function converts only Child->Child, and calls itself for each Sibling
81 VOID
82 ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
83 {
84 PCONFIGURATION_COMPONENT_DATA Child;
85 PCONFIGURATION_COMPONENT_DATA Sibling;
86
87 DPRINTM(DPRINT_WINDOWS, "ConvertConfigToVA(Start 0x%X)\n", Start);
88 Child = Start;
89
90 while (Child != NULL)
91 {
92 if (Child->ConfigurationData)
93 Child->ConfigurationData = PaToVa(Child->ConfigurationData);
94
95 if (Child->Child)
96 Child->Child = PaToVa(Child->Child);
97
98 if (Child->Parent)
99 Child->Parent = PaToVa(Child->Parent);
100
101 if (Child->Sibling)
102 Child->Sibling = PaToVa(Child->Sibling);
103
104 if (Child->ComponentEntry.Identifier)
105 Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);
106
107 DPRINTM(DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Child,
108 Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent);
109
110 // Go through siblings list
111 Sibling = VaToPa(Child->Sibling);
112 while (Sibling != NULL)
113 {
114 if (Sibling->ConfigurationData)
115 Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);
116
117 if (Sibling->Child)
118 Sibling->Child = PaToVa(Sibling->Child);
119
120 if (Sibling->Parent)
121 Sibling->Parent = PaToVa(Sibling->Parent);
122
123 if (Sibling->Sibling)
124 Sibling->Sibling = PaToVa(Sibling->Sibling);
125
126 if (Sibling->ComponentEntry.Identifier)
127 Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier);
128
129 DPRINTM(DPRINT_WINDOWS, "Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
130 Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent);
131
132 // Recurse into the Child tree
133 if (VaToPa(Sibling->Child) != NULL)
134 ConvertConfigToVA(VaToPa(Sibling->Child));
135
136 Sibling = VaToPa(Sibling->Sibling);
137 }
138
139 // Go to the next child
140 Child = VaToPa(Child->Child);
141 }
142 }