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