5c5452a503306416b06e886335ee44037227072d
[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 DBG_DEFAULT_CHANNEL(WINDOWS);
17
18 /* FUNCTIONS **************************************************************/
19
20 #ifndef _ZOOM2_
21 /* Arch-specific addresses translation implementation */
22 PVOID
23 VaToPa(PVOID Va)
24 {
25 return (PVOID)((ULONG_PTR)Va & ~KSEG0_BASE);
26 }
27
28 PVOID
29 PaToVa(PVOID Pa)
30 {
31 return (PVOID)((ULONG_PTR)Pa | KSEG0_BASE);
32 }
33 #else
34 PVOID
35 VaToPa(PVOID Va)
36 {
37 return Va;
38 }
39
40 PVOID
41 PaToVa(PVOID Pa)
42 {
43 return Pa;
44 }
45 #endif
46
47 VOID
48 List_PaToVa(PLIST_ENTRY ListHeadPa)
49 {
50 PLIST_ENTRY EntryPa, NextPa;
51
52 /* List must be properly initialized */
53 ASSERT(ListHeadPa->Flink != 0);
54 ASSERT(ListHeadPa->Blink != 0);
55
56 /* Loop the list in physical address space */
57 EntryPa = ListHeadPa->Flink;
58 while (EntryPa != ListHeadPa)
59 {
60 /* Save the physical address of the next entry */
61 NextPa = EntryPa->Flink;
62
63 /* Convert the addresses of this entry */
64 EntryPa->Flink = PaToVa(EntryPa->Flink);
65 EntryPa->Blink = PaToVa(EntryPa->Blink);
66
67 /* Go to the next entry */
68 EntryPa = NextPa;
69 }
70
71 /* Finally convert the list head */
72 ListHeadPa->Flink = PaToVa(ListHeadPa->Flink);
73 ListHeadPa->Blink = PaToVa(ListHeadPa->Blink);
74 }
75
76 // This function converts only Child->Child, and calls itself for each Sibling
77 VOID
78 ConvertConfigToVA(PCONFIGURATION_COMPONENT_DATA Start)
79 {
80 PCONFIGURATION_COMPONENT_DATA Child;
81 PCONFIGURATION_COMPONENT_DATA Sibling;
82
83 TRACE("ConvertConfigToVA(Start 0x%X)\n", Start);
84 Child = Start;
85
86 while (Child != NULL)
87 {
88 if (Child->ConfigurationData)
89 Child->ConfigurationData = PaToVa(Child->ConfigurationData);
90
91 if (Child->Child)
92 Child->Child = PaToVa(Child->Child);
93
94 if (Child->Parent)
95 Child->Parent = PaToVa(Child->Parent);
96
97 if (Child->Sibling)
98 Child->Sibling = PaToVa(Child->Sibling);
99
100 if (Child->ComponentEntry.Identifier)
101 Child->ComponentEntry.Identifier = PaToVa(Child->ComponentEntry.Identifier);
102
103 TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Child,
104 Child->ComponentEntry.Class, Child->ComponentEntry.Type, VaToPa(Child->ComponentEntry.Identifier), Child->Parent);
105
106 // Go through siblings list
107 Sibling = VaToPa(Child->Sibling);
108 while (Sibling != NULL)
109 {
110 if (Sibling->ConfigurationData)
111 Sibling->ConfigurationData = PaToVa(Sibling->ConfigurationData);
112
113 if (Sibling->Child)
114 Sibling->Child = PaToVa(Sibling->Child);
115
116 if (Sibling->Parent)
117 Sibling->Parent = PaToVa(Sibling->Parent);
118
119 if (Sibling->Sibling)
120 Sibling->Sibling = PaToVa(Sibling->Sibling);
121
122 if (Sibling->ComponentEntry.Identifier)
123 Sibling->ComponentEntry.Identifier = PaToVa(Sibling->ComponentEntry.Identifier);
124
125 TRACE("Device 0x%X class %d type %d id '%s', parent %p\n", Sibling,
126 Sibling->ComponentEntry.Class, Sibling->ComponentEntry.Type, VaToPa(Sibling->ComponentEntry.Identifier), Sibling->Parent);
127
128 // Recurse into the Child tree
129 if (VaToPa(Sibling->Child) != NULL)
130 ConvertConfigToVA(VaToPa(Sibling->Child));
131
132 Sibling = VaToPa(Sibling->Sibling);
133 }
134
135 // Go to the next child
136 Child = VaToPa(Child->Child);
137 }
138 }