Bläddra i källkod

[pxe] Create pxe_[de]activate() wrapper functions

Merge the pxe_set_netdev()+pxe_[un]hook_int1a() pattern into a single
pxe_[de]activate() call.
tags/v0.9.8
Michael Brown 15 år sedan
förälder
incheckning
07b5be3341

+ 6
- 9
src/arch/i386/image/pxe_image.c Visa fil

@@ -44,27 +44,24 @@ struct image_type pxe_image_type __image_type ( PROBE_PXE );
44 44
  * @ret rc		Return status code
45 45
  */
46 46
 static int pxe_exec ( struct image *image ) {
47
+	struct net_device *netdev;
47 48
 	int rc;
48 49
 
49
-	/* Ensure that PXE stack is ready to use */
50
-	pxe_hook_int1a();
51
-
52 50
 	/* Arbitrarily pick the most recently opened network device */
53
-	pxe_set_netdev ( last_opened_netdev() );
54
-
55
-	/* Many things will break if pxe_netdev is NULL */
56
-	if ( ! pxe_netdev ) {
51
+	if ( ( netdev = last_opened_netdev() ) == NULL ) {
57 52
 		DBGC ( image, "IMAGE %p could not locate PXE net device\n",
58 53
 		       image );
59 54
 		return -ENODEV;
60 55
 	}
61 56
 
57
+	/* Activate PXE */
58
+	pxe_activate ( netdev );
59
+
62 60
 	/* Start PXE NBP */
63 61
 	rc = pxe_start_nbp();
64 62
 
65 63
 	/* Deactivate PXE */
66
-	pxe_set_netdev ( NULL );
67
-	pxe_unhook_int1a();
64
+	pxe_deactivate();
68 65
 
69 66
 	return rc;
70 67
 }

+ 4
- 2
src/arch/i386/include/pxe_call.h Visa fil

@@ -11,6 +11,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
11 11
 #include <pxe_api.h>
12 12
 #include <realmode.h>
13 13
 
14
+struct net_device;
15
+
14 16
 /** PXE load address segment */
15 17
 #define PXE_LOAD_SEGMENT 0
16 18
 
@@ -28,8 +30,8 @@ extern struct s_PXE __text16 ( ppxe );
28 30
 extern struct s_PXENV __text16 ( pxenv );
29 31
 #define pxenv __use_text16 ( pxenv )
30 32
 
31
-extern void pxe_hook_int1a ( void );
32
-extern int pxe_unhook_int1a ( void );
33
+extern void pxe_activate ( struct net_device *netdev );
34
+extern int pxe_deactivate ( void );
33 35
 extern int pxe_start_nbp ( void );
34 36
 extern __asmcall void pxe_api_call ( struct i386_all_regs *ix86 );
35 37
 

+ 47
- 19
src/arch/i386/interface/pxe/pxe_call.c Visa fil

@@ -37,6 +37,9 @@ extern struct segoff __text16 ( pxe_int_1a_vector );
37 37
 /** INT 1A handler */
38 38
 extern void pxe_int_1a ( void );
39 39
 
40
+/** INT 1A hooked flag */
41
+static int int_1a_hooked = 0;
42
+
40 43
 /** A function pointer to hold any PXE API call
41 44
  *
42 45
  * Used by pxe_api_call() to avoid large swathes of duplicated code.
@@ -364,25 +367,6 @@ __asmcall void pxe_loader_call ( struct i386_all_regs *ix86 ) {
364 367
 	ix86->regs.ax = ret;
365 368
 }
366 369
 
367
-/**
368
- * Hook INT 1A for PXE
369
- *
370
- */
371
-void pxe_hook_int1a ( void ) {
372
-	hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
373
-			      &pxe_int_1a_vector );
374
-}
375
-
376
-/**
377
- * Unhook INT 1A for PXE
378
- *
379
- * @ret rc		Return status code
380
- */
381
-int pxe_unhook_int1a ( void ) {
382
-	return unhook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
383
-				       &pxe_int_1a_vector );
384
-}
385
-
386 370
 /**
387 371
  * Calculate byte checksum as used by PXE
388 372
  *
@@ -435,6 +419,50 @@ struct init_fn pxe_init_fn __init_fn ( INIT_NORMAL ) = {
435 419
 	.initialise = pxe_init_structures,
436 420
 };
437 421
 
422
+/**
423
+ * Activate PXE stack
424
+ *
425
+ * @v netdev		Net device to use as PXE net device
426
+ */
427
+void pxe_activate ( struct net_device *netdev ) {
428
+
429
+	/* Ensure INT 1A is hooked */
430
+	if ( ! int_1a_hooked ) {
431
+		hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
432
+				      &pxe_int_1a_vector );
433
+		int_1a_hooked = 1;
434
+	}
435
+
436
+	/* Set PXE network device */
437
+	pxe_set_netdev ( netdev );
438
+}
439
+
440
+/**
441
+ * Deactivate PXE stack
442
+ *
443
+ * @ret rc		Return status code
444
+ */
445
+int pxe_deactivate ( void ) {
446
+	int rc;
447
+
448
+	/* Clear PXE network device */
449
+	pxe_set_netdev ( NULL );
450
+
451
+	/* Ensure INT 1A is unhooked, if possible */
452
+	if ( int_1a_hooked ) {
453
+		if ( ( rc = unhook_bios_interrupt ( 0x1a,
454
+						    (unsigned int) pxe_int_1a,
455
+						    &pxe_int_1a_vector ))!= 0){
456
+			DBG ( "Could not unhook INT 1A: %s\n",
457
+			      strerror ( rc ) );
458
+			return rc;
459
+		}
460
+		int_1a_hooked = 0;
461
+	}
462
+
463
+	return 0;
464
+}
465
+
438 466
 /**
439 467
  * Start PXE NBP at 0000:7c00
440 468
  *

+ 4
- 10
src/arch/i386/interface/pxe/pxe_preboot.c Visa fil

@@ -296,11 +296,8 @@ PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
296 296
 	}
297 297
 	DBG ( " using netdev %s", netdev->name );
298 298
 
299
-	/* Save as PXE net device */
300
-	pxe_set_netdev ( netdev );
301
-
302
-	/* Hook INT 1A */
303
-	pxe_hook_int1a();
299
+	/* Activate PXE */
300
+	pxe_activate ( netdev );
304 301
 
305 302
 	start_undi->Status = PXENV_STATUS_SUCCESS;
306 303
 	return PXENV_EXIT_SUCCESS;
@@ -313,11 +310,8 @@ PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
313 310
 PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
314 311
 	DBG ( "PXENV_STOP_UNDI" );
315 312
 
316
-	/* Unhook INT 1A */
317
-	pxe_unhook_int1a();
318
-
319
-	/* Clear PXE net device */
320
-	pxe_set_netdev ( NULL );
313
+	/* Deactivate PXE */
314
+	pxe_deactivate();
321 315
 
322 316
 	/* Prepare for unload */
323 317
 	shutdown ( SHUTDOWN_BOOT );

Laddar…
Avbryt
Spara