]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Ebl/HwIoDebug.c
Adding support for BeagleBoard.
[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
27 Argv[0] - "ioread"\r
28 Argv[1] - Hex IO address\r
29 Argv[2] - IO Width [1|2|4] with a default of 1\r
30\r
31 ior 0x3f8 4 ;Do a 32-bit IO Read from 0x3f8\r
32 ior 0x3f8 1 ;Do a 8-bit IO Read from 0x3f8\r
33\r
34 @param Argc Number of command arguments in Argv\r
35 @param Argv Array of strings that represent the parsed command line. \r
36 Argv[0] is the comamnd name\r
37\r
38 @return EFI_SUCCESS\r
39\r
40**/\r
41EFI_STATUS\r
42EblIoReadCmd (\r
43 IN UINTN Argc,\r
44 IN CHAR8 **Argv\r
45 )\r
46{\r
47 UINTN Width;\r
48 UINTN Port;\r
49 UINTN Data;\r
50\r
51 if (Argc < 2) {\r
52 return EFI_INVALID_PARAMETER;\r
53 }\r
54\r
55 Port = AsciiStrHexToUintn (Argv[1]);\r
56 Width = (Argc > 2) ? AsciiStrHexToUintn (Argv[2]) : 1;\r
57\r
58 if (Width == 1) {\r
59 Data = IoRead8 (Port);\r
60 } else if (Width == 2) {\r
61 Data = IoRead16 (Port);\r
62 } else if (Width == 4) {\r
63 Data = IoRead32 (Port);\r
64 } else {\r
65 return EFI_INVALID_PARAMETER;\r
66 }\r
67\r
68 AsciiPrint ("0x%04x = 0x%x", Port, Data);\r
69\r
70 return EFI_SUCCESS;\r
71}\r
72\r
73\r
74/**\r
75 Write to IO space\r
76\r
77 Argv[0] - "iowrite"\r
78 Argv[1] - Hex IO address\r
79 Argv[2] - Hex data to write\r
80 Argv[3] - IO Width [1|2|4] with a default of 1\r
81\r
82 iow 0x3f8 af 4 ;Do a 32-bit IO write of af to 0x3f8\r
83 iow 0x3f8 af ;Do an 8-bit IO write of af to 0x3f8\r
84\r
85 @param Argc Number of command arguments in Argv\r
86 @param Argv Array of strings that represent the parsed command line. \r
87 Argv[0] is the comamnd name\r
88\r
89 @return EFI_SUCCESS\r
90\r
91**/\r
92EFI_STATUS\r
93EblIoWriteCmd (\r
94 IN UINTN Argc,\r
95 IN CHAR8 **Argv\r
96 )\r
97{\r
98 UINTN Width;\r
99 UINTN Port;\r
100 UINTN Data;\r
101\r
102 if (Argc < 3) {\r
103 return EFI_INVALID_PARAMETER;\r
104 }\r
105\r
106 Port = AsciiStrHexToUintn (Argv[1]);\r
107 Data = AsciiStrHexToUintn (Argv[2]);\r
108 Width = (Argc > 3) ? AsciiStrHexToUintn (Argv[3]) : 1;\r
109 \r
110 if (Width == 1) {\r
111 IoWrite8 (Port, (UINT8)Data);\r
112 } else if (Width == 2) {\r
113 IoWrite16 (Port, (UINT16)Data);\r
114 } else if (Width == 4) {\r
115 IoWrite32 (Port, (UINT32)Data);\r
116 } else {\r
117 return EFI_INVALID_PARAMETER;\r
118 }\r
119 return EFI_SUCCESS;\r
120}\r
121\r
122\r
123GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdHwIoDebugTemplate[] =\r
124{\r
125 {\r
126 "ioread",\r
127 " Port [1|2|4]; IO read of width[1] byte(s) from Port",\r
128 NULL,\r
129 EblIoReadCmd\r
130 },\r
131 {\r
132 "iowrite",\r
133 " Port Data [1|2|4]; IO write Data of width[1] byte(s) to Port",\r
134 NULL,\r
135 EblIoWriteCmd\r
136 }\r
137};\r
138\r
139\r
140\r
141/**\r
142 Initialize the commands in this in this file\r
143**/\r
144VOID\r
145EblInitializemdHwIoDebugCmds (\r
146 VOID\r
147 )\r
148{\r
149 if (FeaturePcdGet (PcdEmbeddedIoEnable)) {\r
150 EblAddCommands (mCmdHwIoDebugTemplate, sizeof (mCmdHwIoDebugTemplate)/sizeof (EBL_COMMAND_TABLE));\r
151 }\r
152}\r
153\r