瀏覽代碼

[efi] Add ability to dump all openers of a given protocol on a handle

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 年之前
父節點
當前提交
736fcf60d1
共有 2 個檔案被更改,包括 106 行新增4 行删除
  1. 26
    1
      src/include/ipxe/efi/efi.h
  2. 80
    3
      src/interface/efi/efi_debug.c

+ 26
- 1
src/include/ipxe/efi/efi.h 查看文件

@@ -153,22 +153,47 @@ extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
153 153
 extern const char * efi_handle_devpath_text ( EFI_HANDLE handle );
154 154
 extern const char * efi_handle_name ( EFI_HANDLE handle );
155 155
 
156
+extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
156 157
 extern void dbg_efi_protocols ( EFI_HANDLE handle );
157 158
 
159
+#define DBG_EFI_OPENERS_IF( level, handle, protocol ) do {	\
160
+		if ( DBG_ ## level ) {				\
161
+			dbg_efi_openers ( handle, protocol );	\
162
+		}						\
163
+	} while ( 0 )
164
+
158 165
 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {		\
159 166
 		if ( DBG_ ## level ) {				\
160 167
 			dbg_efi_protocols ( handle );		\
161 168
 		}						\
162 169
 	} while ( 0 )
163 170
 
171
+#define DBGC_EFI_OPENERS_IF( level, id, ... ) do {		\
172
+		DBG_AC_IF ( level, id );			\
173
+		DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ );	\
174
+		DBG_DC_IF ( level );				\
175
+	} while ( 0 )
176
+
164 177
 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {		\
165 178
 		DBG_AC_IF ( level, id );			\
166 179
 		DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );	\
167 180
 		DBG_DC_IF ( level );				\
168 181
 	} while ( 0 )
169 182
 
183
+#define DBGC_EFI_OPENERS( ... )					\
184
+	DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
170 185
 #define DBGC_EFI_PROTOCOLS( ... )				\
171
-	DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
186
+	DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
187
+
188
+#define DBGC2_EFI_OPENERS( ... )				\
189
+	DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
190
+#define DBGC2_EFI_PROTOCOLS( ... )				\
191
+	DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
192
+
193
+#define DBGCP_EFI_OPENERS( ... )				\
194
+	DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
195
+#define DBGCP_EFI_PROTOCOLS( ... )				\
196
+	DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
172 197
 
173 198
 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
174 199
 			     EFI_SYSTEM_TABLE *systab );

+ 80
- 3
src/interface/efi/efi_debug.c 查看文件

@@ -183,6 +183,77 @@ const char * efi_guid_ntoa ( EFI_GUID *guid ) {
183 183
 	return uuid_ntoa ( &u.uuid );
184 184
 }
185 185
 
186
+/**
187
+ * Name protocol open attributes
188
+ *
189
+ * @v attributes	Protocol open attributes
190
+ * @ret name		Protocol open attributes name
191
+ *
192
+ * Returns a (static) string with characters for each set bit
193
+ * corresponding to BY_(H)ANDLE_PROTOCOL, (G)ET_PROTOCOL,
194
+ * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and
195
+ * E(X)CLUSIVE.
196
+ */
197
+static const char * efi_open_attributes_name ( unsigned int attributes ) {
198
+	static char attribute_chars[] = "HGTCDX";
199
+	static char name[ sizeof ( attribute_chars ) ];
200
+	char *tmp = name;
201
+	unsigned int i;
202
+
203
+	for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
204
+		if ( attributes & ( 1 << i ) )
205
+			*(tmp++) = attribute_chars[i];
206
+	}
207
+	*tmp = '\0';
208
+
209
+	return name;
210
+}
211
+
212
+/**
213
+ * Print list of openers of a given protocol on a given handle
214
+ *
215
+ * @v handle		EFI handle
216
+ * @v protocol		Protocol GUID
217
+ */
218
+void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) {
219
+	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
220
+	EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
221
+	EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
222
+	UINTN count;
223
+	unsigned int i;
224
+	EFI_STATUS efirc;
225
+	int rc;
226
+
227
+	/* Retrieve list of openers */
228
+	if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
229
+						     &count ) ) != 0 ) {
230
+		rc = -EEFI ( efirc );
231
+		printf ( "EFI could not retrieve openers for %s on %p: %s\n",
232
+			 efi_guid_ntoa ( protocol ), handle, strerror ( rc ) );
233
+		return;
234
+	}
235
+
236
+	/* Dump list of openers */
237
+	for ( i = 0 ; i < count ; i++ ) {
238
+		opener = &openers[i];
239
+		printf ( "HANDLE %p %s %s opened %dx (%s)",
240
+			 handle, efi_handle_name ( handle ),
241
+			 efi_guid_ntoa ( protocol ), opener->OpenCount,
242
+			 efi_open_attributes_name ( opener->Attributes ) );
243
+		printf ( " by %p %s", opener->AgentHandle,
244
+			 efi_handle_name ( opener->AgentHandle ) );
245
+		if ( opener->ControllerHandle == handle ) {
246
+			printf ( "\n" );
247
+		} else {
248
+			printf ( " for %p %s\n", opener->ControllerHandle,
249
+				 efi_handle_name ( opener->ControllerHandle ) );
250
+		}
251
+	}
252
+
253
+	/* Free list */
254
+	bs->FreePool ( openers );
255
+}
256
+
186 257
 /**
187 258
  * Print list of protocol handlers attached to a handle
188 259
  *
@@ -190,7 +261,8 @@ const char * efi_guid_ntoa ( EFI_GUID *guid ) {
190 261
  */
191 262
 void dbg_efi_protocols ( EFI_HANDLE handle ) {
192 263
 	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
193
-        EFI_GUID **protocols;
264
+	EFI_GUID **protocols;
265
+	EFI_GUID *protocol;
194 266
 	UINTN count;
195 267
 	unsigned int i;
196 268
 	EFI_STATUS efirc;
@@ -206,8 +278,13 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
206 278
 	}
207 279
 
208 280
 	/* Dump list of protocols */
209
-	for ( i = 0 ; i < count ; i++ )
210
-		printf ( "%s\n", efi_guid_ntoa ( protocols[i] ) );
281
+	for ( i = 0 ; i < count ; i++ ) {
282
+		protocol = protocols[i];
283
+		printf ( "HANDLE %p %s %s supported\n",
284
+			 handle, efi_handle_name ( handle ),
285
+			 efi_guid_ntoa ( protocol ) );
286
+		dbg_efi_openers ( handle, protocol );
287
+	}
211 288
 
212 289
 	/* Free list */
213 290
 	bs->FreePool ( protocols );

Loading…
取消
儲存