Commit ebb4dd5bc3d39b3a2109970936c7e74556110915

Authored by Heinrich Schuchardt
Committed by Alexander Graf
1 parent 48b66230ee

efi_loader: efi_console: use helper functions

Use helper functions efi_created_handle and efi_add_protocol
for creating the console handles and instaling the respective
protocols.

This change is needed if we want to move from an array of
protocols to a linked list of protocols.

Eliminate EFI_PROTOCOL_OBJECT which is not used anymore.

Currently we have not defined protocol interfaces to be const.
So efi_con_out and efi_console_control cannot be defined as const.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>

Showing 2 changed files with 37 additions and 23 deletions Side-by-side Diff

include/efi_loader.h
... ... @@ -78,9 +78,9 @@
78 78 extern struct efi_runtime_services efi_runtime_services;
79 79 extern struct efi_system_table systab;
80 80  
81   -extern const struct efi_simple_text_output_protocol efi_con_out;
  81 +extern struct efi_simple_text_output_protocol efi_con_out;
82 82 extern struct efi_simple_input_interface efi_con_in;
83   -extern const struct efi_console_control_protocol efi_console_control;
  83 +extern struct efi_console_control_protocol efi_console_control;
84 84 extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
85 85  
86 86 uint16_t *efi_dp_str(struct efi_device_path *dp);
... ... @@ -120,14 +120,6 @@
120 120 /* The object spawner can either use this for data or as identifier */
121 121 void *handle;
122 122 };
123   -
124   -#define EFI_PROTOCOL_OBJECT(_guid, _protocol) (struct efi_object){ \
125   - .protocols = {{ \
126   - .guid = &(_guid), \
127   - .protocol_interface = (void *)(_protocol), \
128   - }}, \
129   - .handle = (void *)(_protocol), \
130   -}
131 123  
132 124 /**
133 125 * struct efi_event
lib/efi_loader/efi_console.c
... ... @@ -46,6 +46,10 @@
46 46 };
47 47  
48 48 const efi_guid_t efi_guid_console_control = CONSOLE_CONTROL_GUID;
  49 +const efi_guid_t efi_guid_text_output_protocol =
  50 + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID;
  51 +const efi_guid_t efi_guid_text_input_protocol =
  52 + EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
49 53  
50 54 #define cESC '\x1b'
51 55 #define ESC "\x1b"
... ... @@ -81,7 +85,7 @@
81 85 return EFI_EXIT(EFI_UNSUPPORTED);
82 86 }
83 87  
84   -const struct efi_console_control_protocol efi_console_control = {
  88 +struct efi_console_control_protocol efi_console_control = {
85 89 .get_mode = efi_cin_get_mode,
86 90 .set_mode = efi_cin_set_mode,
87 91 .lock_std_in = efi_cin_lock_std_in,
... ... @@ -374,7 +378,7 @@
374 378 return EFI_EXIT(EFI_SUCCESS);
375 379 }
376 380  
377   -const struct efi_simple_text_output_protocol efi_con_out = {
  381 +struct efi_simple_text_output_protocol efi_con_out = {
378 382 .reset = efi_cout_reset,
379 383 .output_string = efi_cout_output_string,
380 384 .test_string = efi_cout_test_string,
381 385  
382 386  
383 387  
... ... @@ -490,23 +494,38 @@
490 494 }
491 495  
492 496  
493   -static struct efi_object efi_console_control_obj =
494   - EFI_PROTOCOL_OBJECT(efi_guid_console_control, &efi_console_control);
495   -static struct efi_object efi_console_output_obj =
496   - EFI_PROTOCOL_OBJECT(EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, &efi_con_out);
497   -static struct efi_object efi_console_input_obj =
498   - EFI_PROTOCOL_OBJECT(EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, &efi_con_in);
499   -
500 497 /* This gets called from do_bootefi_exec(). */
501 498 int efi_console_register(void)
502 499 {
503 500 efi_status_t r;
  501 + struct efi_object *efi_console_control_obj;
  502 + struct efi_object *efi_console_output_obj;
  503 + struct efi_object *efi_console_input_obj;
504 504  
505   - /* Hook up to the device list */
506   - list_add_tail(&efi_console_control_obj.link, &efi_obj_list);
507   - list_add_tail(&efi_console_output_obj.link, &efi_obj_list);
508   - list_add_tail(&efi_console_input_obj.link, &efi_obj_list);
  505 + /* Create handles */
  506 + r = efi_create_handle((void **)&efi_console_control_obj);
  507 + if (r != EFI_SUCCESS)
  508 + goto out_of_memory;
  509 + r = efi_add_protocol(efi_console_control_obj->handle,
  510 + &efi_guid_console_control, &efi_console_control);
  511 + if (r != EFI_SUCCESS)
  512 + goto out_of_memory;
  513 + r = efi_create_handle((void **)&efi_console_output_obj);
  514 + if (r != EFI_SUCCESS)
  515 + goto out_of_memory;
  516 + r = efi_add_protocol(efi_console_output_obj->handle,
  517 + &efi_guid_text_output_protocol, &efi_con_out);
  518 + if (r != EFI_SUCCESS)
  519 + goto out_of_memory;
  520 + r = efi_create_handle((void **)&efi_console_input_obj);
  521 + if (r != EFI_SUCCESS)
  522 + goto out_of_memory;
  523 + r = efi_add_protocol(efi_console_input_obj->handle,
  524 + &efi_guid_text_input_protocol, &efi_con_in);
  525 + if (r != EFI_SUCCESS)
  526 + goto out_of_memory;
509 527  
  528 + /* Create console events */
510 529 r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
511 530 efi_key_notify, NULL, &efi_con_in.wait_for_key);
512 531 if (r != EFI_SUCCESS) {
... ... @@ -524,6 +543,9 @@
524 543 r = efi_set_timer(console_timer_event, EFI_TIMER_PERIODIC, 50);
525 544 if (r != EFI_SUCCESS)
526 545 printf("ERROR: Failed to set console timer\n");
  546 + return r;
  547 +out_of_memory:
  548 + printf("ERROR: Out of meemory\n");
527 549 return r;
528 550 }