]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Ebl/HwIoDebug.c
Update EBL to have an optional width specifier on commands. So hexdump.4 means use...
[mirror_edk2.git] / EmbeddedPkg / Ebl / HwIoDebug.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Hardware IO based debug commands\r
3\r
4 Copyright (c) 2007, Intel Corporation<BR>\r
5 Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
6\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 Commands useful for debugging hardware. IO commands seperated out as not all\r
16 processor architectures support the IO command.\r
17\r
18**/\r
19\r
20#include "Ebl.h"\r
21\r
22\r
23\r
24/**\r
25 Read from IO space\r
26\r
a6d7123e 27 Argv[0] - "ioread"[.#] # is optiona width 1, 2, or 4. Default 1\r
2ef2b01e 28 Argv[1] - Hex IO address\r
2ef2b01e 29\r
a6d7123e 30 ior.4 0x3f8 ;Do a 32-bit IO Read from 0x3f8\r
31 ior 0x3f8 ;Do a 8-bit IO Read from 0x3f8\r
2ef2b01e
A
32\r
33 @param Argc Number of command arguments in Argv\r
34 @param Argv Array of strings that represent the parsed command line. \r
35 Argv[0] is the comamnd name\r
36\r
37 @return EFI_SUCCESS\r
38\r
39**/\r
40EFI_STATUS\r
41EblIoReadCmd (\r
42 IN UINTN Argc,\r
43 IN CHAR8 **Argv\r
44 )\r
45{\r
46 UINTN Width;\r
47 UINTN Port;\r
48 UINTN Data;\r
49\r
50 if (Argc < 2) {\r
51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 Port = AsciiStrHexToUintn (Argv[1]);\r
a6d7123e 55 Width = WidthFromCommandName (Argv[0], 1);\r
2ef2b01e
A
56\r
57 if (Width == 1) {\r
58 Data = IoRead8 (Port);\r
59 } else if (Width == 2) {\r
60 Data = IoRead16 (Port);\r
61 } else if (Width == 4) {\r
62 Data = IoRead32 (Port);\r
63 } else {\r
64 return EFI_INVALID_PARAMETER;\r
65 }\r
66\r
67 AsciiPrint ("0x%04x = 0x%x", Port, Data);\r
68\r
69 return EFI_SUCCESS;\r
70}\r
71\r
72\r
73/**\r
74 Write to IO space\r
75\r
a6d7123e 76 Argv[0] - "iowrite"[.#] # is optiona width 1, 2, or 4. Default 1\r
2ef2b01e
A
77 Argv[1] - Hex IO address\r
78 Argv[2] - Hex data to write\r
2ef2b01e 79\r
a6d7123e 80 iow.4 0x3f8 af ;Do a 32-bit IO write of af to 0x3f8\r
81 iow 0x3f8 af ;Do an 8-bit IO write of af to 0x3f8\r
2ef2b01e
A
82\r
83 @param Argc Number of command arguments in Argv\r
84 @param Argv Array of strings that represent the parsed command line. \r
85 Argv[0] is the comamnd name\r
86\r
87 @return EFI_SUCCESS\r
88\r
89**/\r
90EFI_STATUS\r
91EblIoWriteCmd (\r
92 IN UINTN Argc,\r
93 IN CHAR8 **Argv\r
94 )\r
95{\r
96 UINTN Width;\r
97 UINTN Port;\r
98 UINTN Data;\r
99\r
100 if (Argc < 3) {\r
101 return EFI_INVALID_PARAMETER;\r
102 }\r
103\r
104 Port = AsciiStrHexToUintn (Argv[1]);\r
105 Data = AsciiStrHexToUintn (Argv[2]);\r
a6d7123e 106 Width = WidthFromCommandName (Argv[0], 1);\r
2ef2b01e
A
107 \r
108 if (Width == 1) {\r
109 IoWrite8 (Port, (UINT8)Data);\r
110 } else if (Width == 2) {\r
111 IoWrite16 (Port, (UINT16)Data);\r
112 } else if (Width == 4) {\r
113 IoWrite32 (Port, (UINT32)Data);\r
114 } else {\r
115 return EFI_INVALID_PARAMETER;\r
116 }\r
117 return EFI_SUCCESS;\r
118}\r
119\r
120\r
121GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdHwIoDebugTemplate[] =\r
122{\r
123 {\r
124 "ioread",\r
a6d7123e 125 "[.{1|2|4}] Port ; IO read of width byte(s) from Port",\r
2ef2b01e
A
126 NULL,\r
127 EblIoReadCmd\r
128 },\r
129 {\r
130 "iowrite",\r
a6d7123e 131 "[.{1|2|4}] Port Data ; IO write Data of width byte(s) to Port",\r
2ef2b01e
A
132 NULL,\r
133 EblIoWriteCmd\r
134 }\r
135};\r
136\r
137\r
138\r
139/**\r
140 Initialize the commands in this in this file\r
141**/\r
142VOID\r
143EblInitializemdHwIoDebugCmds (\r
144 VOID\r
145 )\r
146{\r
147 if (FeaturePcdGet (PcdEmbeddedIoEnable)) {\r
148 EblAddCommands (mCmdHwIoDebugTemplate, sizeof (mCmdHwIoDebugTemplate)/sizeof (EBL_COMMAND_TABLE));\r
149 }\r
150}\r
151\r