]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Sockets/WebServer/MemoryMap.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Sockets / WebServer / MemoryMap.c
1 /**
2 @file
3 Display the memory map
4
5 Copyright (c) 2012, Intel Corporation. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <WebServer.h>
11 #include <PiDxe.h>
12 #include <Library/DxeServicesTableLib.h>
13
14
15 CONST char * mpMemoryType[ ] = {
16 "Non-existent",
17 "Reserved",
18 "System Memory",
19 "Memory Mapped I/O"
20 };
21
22
23 /**
24 Page to display the memory map
25
26 @param [in] SocketFD The socket's file descriptor to add to the list.
27 @param [in] pPort The WSDT_PORT structure address
28 @param [out] pbDone Address to receive the request completion status
29
30 @retval EFI_SUCCESS The request was successfully processed
31
32 **/
33 EFI_STATUS
34 MemoryMapPage (
35 IN int SocketFD,
36 IN WSDT_PORT * pPort,
37 OUT BOOLEAN * pbDone
38 )
39 {
40 UINT64 Attributes;
41 BOOLEAN bSomethingDisplayed;
42 UINTN Count;
43 EFI_GCD_MEMORY_SPACE_DESCRIPTOR * pMemoryEnd;
44 EFI_GCD_MEMORY_SPACE_DESCRIPTOR * pMemoryDescriptor;
45 EFI_GCD_MEMORY_SPACE_DESCRIPTOR * pMemoryDescriptorStart;
46 EFI_STATUS Status;
47
48 DBG_ENTER ( );
49
50 //
51 // Send the memory map page
52 //
53 pMemoryDescriptorStart = NULL;
54 for ( ; ; ) {
55 //
56 // Send the page header
57 //
58 Status = HttpPageHeader ( SocketFD, pPort, L"Memory Map" );
59 if ( EFI_ERROR ( Status )) {
60 break;
61 }
62
63 //
64 // Start the table
65 //
66 Status = HttpSendAnsiString ( SocketFD,
67 pPort,
68 "<h1>Memory Map</h1>\r\n"
69 "<table>\r\n"
70 " <tr><th align=\"right\">Type</th><th align=\"right\">Start</th><th align=\"right\">End</th><th align=\"right\">Attributes</th></tr>\r\n" );
71 if ( EFI_ERROR ( Status )) {
72 break;
73 }
74
75 //
76 // Get the memory map
77 //
78 Status = gDS->GetMemorySpaceMap ( &Count,
79 &pMemoryDescriptor );
80 if ( !EFI_ERROR ( Status )) {
81 pMemoryDescriptorStart = pMemoryDescriptor;
82 pMemoryEnd = &pMemoryDescriptor[ Count ];
83 while ( pMemoryEnd > pMemoryDescriptor ) {
84 //
85 // Display the type
86 //
87 Status = HttpSendAnsiString ( SocketFD, pPort, "<tr><td align=\"right\"><code>" );
88 if ( EFI_ERROR ( Status )) {
89 break;
90 }
91 if ( DIM ( mpMemoryType ) > pMemoryDescriptor->GcdMemoryType ) {
92 Status = HttpSendAnsiString ( SocketFD,
93 pPort,
94 mpMemoryType[ pMemoryDescriptor->GcdMemoryType ]);
95 }
96 else {
97 Status = HttpSendValue ( SocketFD,
98 pPort,
99 pMemoryDescriptor->GcdMemoryType );
100 }
101 if ( EFI_ERROR ( Status )) {
102 break;
103 }
104
105 //
106 // Display the start address
107 //
108 Status = HttpSendAnsiString ( SocketFD, pPort, "</code></td><td align=\"right\"><code>0x" );
109 if ( EFI_ERROR ( Status )) {
110 break;
111 }
112 Status = HttpSendHexValue ( SocketFD,
113 pPort,
114 pMemoryDescriptor->BaseAddress );
115 if ( EFI_ERROR ( Status )) {
116 break;
117 }
118
119 //
120 // Display the end address
121 //
122 Status = HttpSendAnsiString ( SocketFD, pPort, "</code></td><td align=\"right\"><code>0x" );
123 if ( EFI_ERROR ( Status )) {
124 break;
125 }
126 Status = HttpSendHexValue ( SocketFD,
127 pPort,
128 pMemoryDescriptor->BaseAddress
129 + pMemoryDescriptor->Length
130 - 1 );
131 if ( EFI_ERROR ( Status )) {
132 break;
133 }
134
135 //
136 // Display the attributes
137 //
138 Status = HttpSendAnsiString ( SocketFD, pPort, "</code></td><td align=\"right\"><code>0x" );
139 if ( EFI_ERROR ( Status )) {
140 break;
141 }
142 Status = HttpSendHexValue ( SocketFD,
143 pPort,
144 pMemoryDescriptor->Attributes );
145 if ( EFI_ERROR ( Status )) {
146 break;
147 }
148
149 //
150 // Decode the attributes
151 //
152 Status = HttpSendAnsiString ( SocketFD, pPort, "</code></td><td>" );
153 if ( EFI_ERROR ( Status )) {
154 break;
155 }
156 bSomethingDisplayed = FALSE;
157 Attributes = pMemoryDescriptor->Attributes;
158
159 if ( 0 != ( Attributes & EFI_MEMORY_RUNTIME )) {
160 bSomethingDisplayed = TRUE;
161 Status = HttpSendAnsiString ( SocketFD,
162 pPort,
163 "Runtime" );
164 if ( EFI_ERROR ( Status )) {
165 break;
166 }
167 }
168
169 if ( 0 != ( Attributes & EFI_MEMORY_XP )) {
170 if ( bSomethingDisplayed ) {
171 Status = HttpSendAnsiString ( SocketFD,
172 pPort,
173 ", " );
174 if ( EFI_ERROR ( Status )) {
175 break;
176 }
177 }
178 bSomethingDisplayed = TRUE;
179 Status = HttpSendAnsiString ( SocketFD,
180 pPort,
181 "No Execute" );
182 if ( EFI_ERROR ( Status )) {
183 break;
184 }
185 }
186
187 if ( 0 != ( Attributes & EFI_MEMORY_RP )) {
188 if ( bSomethingDisplayed ) {
189 Status = HttpSendAnsiString ( SocketFD,
190 pPort,
191 ", " );
192 if ( EFI_ERROR ( Status )) {
193 break;
194 }
195 }
196 bSomethingDisplayed = TRUE;
197 Status = HttpSendAnsiString ( SocketFD,
198 pPort,
199 "No Read" );
200 if ( EFI_ERROR ( Status )) {
201 break;
202 }
203 }
204
205 if ( 0 != ( Attributes & EFI_MEMORY_WP )) {
206 if ( bSomethingDisplayed ) {
207 Status = HttpSendAnsiString ( SocketFD,
208 pPort,
209 ", " );
210 if ( EFI_ERROR ( Status )) {
211 break;
212 }
213 }
214 bSomethingDisplayed = TRUE;
215 Status = HttpSendAnsiString ( SocketFD,
216 pPort,
217 "No Write" );
218 if ( EFI_ERROR ( Status )) {
219 break;
220 }
221 }
222
223 if ( 0 != ( Attributes & EFI_MEMORY_UCE )) {
224 if ( bSomethingDisplayed ) {
225 Status = HttpSendAnsiString ( SocketFD,
226 pPort,
227 ", " );
228 if ( EFI_ERROR ( Status )) {
229 break;
230 }
231 }
232 bSomethingDisplayed = TRUE;
233 Status = HttpSendAnsiString ( SocketFD,
234 pPort,
235 "UCE" );
236 if ( EFI_ERROR ( Status )) {
237 break;
238 }
239 }
240
241
242 if ( 0 != ( Attributes & EFI_MEMORY_WB )) {
243 if ( bSomethingDisplayed ) {
244 Status = HttpSendAnsiString ( SocketFD,
245 pPort,
246 ", " );
247 if ( EFI_ERROR ( Status )) {
248 break;
249 }
250 }
251 bSomethingDisplayed = TRUE;
252 Status = HttpSendAnsiString ( SocketFD,
253 pPort,
254 "Write Back" );
255 if ( EFI_ERROR ( Status )) {
256 break;
257 }
258 }
259
260 if ( 0 != ( Attributes & EFI_MEMORY_WT )) {
261 if ( bSomethingDisplayed ) {
262 Status = HttpSendAnsiString ( SocketFD,
263 pPort,
264 ", " );
265 if ( EFI_ERROR ( Status )) {
266 break;
267 }
268 }
269 bSomethingDisplayed = TRUE;
270 Status = HttpSendAnsiString ( SocketFD,
271 pPort,
272 "Write Through" );
273 if ( EFI_ERROR ( Status )) {
274 break;
275 }
276 }
277
278 if ( 0 != ( Attributes & EFI_MEMORY_WC )) {
279 if ( bSomethingDisplayed ) {
280 Status = HttpSendAnsiString ( SocketFD,
281 pPort,
282 ", " );
283 if ( EFI_ERROR ( Status )) {
284 break;
285 }
286 }
287 bSomethingDisplayed = TRUE;
288 Status = HttpSendAnsiString ( SocketFD,
289 pPort,
290 "Write Combining" );
291 if ( EFI_ERROR ( Status )) {
292 break;
293 }
294 }
295
296 if ( 0 != ( Attributes & EFI_MEMORY_UC )) {
297 if ( bSomethingDisplayed ) {
298 Status = HttpSendAnsiString ( SocketFD,
299 pPort,
300 ", " );
301 if ( EFI_ERROR ( Status )) {
302 break;
303 }
304 }
305 bSomethingDisplayed = TRUE;
306 Status = HttpSendAnsiString ( SocketFD,
307 pPort,
308 "Uncached" );
309 if ( EFI_ERROR ( Status )) {
310 break;
311 }
312 }
313
314 //
315 // Finish the row
316 //
317 Status = HttpSendAnsiString ( SocketFD, pPort, "</td></tr>" );
318 if ( EFI_ERROR ( Status )) {
319 break;
320 }
321
322 //
323 // Set the next memory descriptor
324 //
325 pMemoryDescriptor += 1;
326 }
327 }
328
329 //
330 // Finish the table
331 //
332 Status = HttpSendAnsiString ( SocketFD,
333 pPort,
334 "</table>\r\n" );
335 if ( EFI_ERROR ( Status )) {
336 break;
337 }
338
339 //
340 // Send the page trailer
341 //
342 Status = HttpPageTrailer ( SocketFD, pPort, pbDone );
343 break;
344 }
345
346 //
347 // Release the memory descriptors
348 //
349 if ( NULL != pMemoryDescriptorStart ) {
350 FreePool ( pMemoryDescriptorStart );
351 }
352
353 //
354 // Return the operation status
355 //
356 DBG_EXIT_STATUS ( Status );
357 return Status;
358 }