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