1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
11 #include <dm/ofnode_decl.h>
12 #include <linux/list.h>
19 * enum expo_id_t - standard expo IDs
21 * These are assumed to be in use at all times. Expos should use IDs starting
22 * from EXPOID_BASE_ID,
24 * @EXPOID_NONE: Not used, invalid ID 0
25 * @EXPOID_SAVE: User has requested that the expo data be saved
26 * @EXPOID_DISCARD: User has requested that the expo data be discarded
27 * @EXPOID_BASE_ID: First ID which can be used for expo objects
39 * enum expoact_type - types of actions reported by the expo
41 * @EXPOACT_NONE: no action
42 * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
43 * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
44 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
45 * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
47 * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
48 * @EXPOACT_QUIT: request to exit the menu
61 * struct expo_action - an action report by the expo
63 * @type: Action type (EXPOACT_NONE if there is no action)
64 * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
65 * @select.id: ID number of the object affected.
68 enum expoact_type type
;
77 * struct expo_theme - theme for the expo
79 * @font_size: Default font size for all text
80 * @menu_inset: Inset width (on each side and top/bottom) for menu items
81 * @menuitem_gap_y: Gap between menu items in pixels
82 * @menu_title_margin_x: Gap between right side of menu title and left size of
89 u32 menu_title_margin_x
;
93 * struct expo - information about an expo
95 * A group of scenes which can be presented to the user, typically to obtain
96 * input or to make a selection.
98 * @name: Name of the expo (allocated)
99 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
100 * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
101 * @scene_id: Current scene ID (0 if none)
102 * @next_id: Next ID number to use, for automatic allocation
103 * @action: Action selected by user. At present only one is supported, with the
104 * type set to EXPOACT_NONE if there is no action
105 * @text_mode: true to use text mode for the menu (no vidconsole)
106 * @popup: true to use popup menus, instead of showing all items
107 * @priv: Private data for the controller
108 * @theme: Information about fonts styles, etc.
109 * @scene_head: List of scenes
110 * @str_head: list of strings
114 struct udevice
*display
;
115 struct udevice
*cons
;
118 struct expo_action action
;
122 struct expo_theme theme
;
123 struct list_head scene_head
;
124 struct list_head str_head
;
128 * struct expo_string - a string that can be used in an expo
130 * @id: ID number of the string
132 * @sibling: Node to link this object to its siblings
137 struct list_head sibling
;
141 * struct scene - information about a scene in an expo
143 * A collection of text/image/menu items in an expo
145 * @expo: Expo this scene is part of
146 * @name: Name of the scene (allocated)
147 * @id: ID number of the scene
148 * @title_id: String ID of title of the scene (allocated)
149 * @highlight_id: ID of highlighted object, if any
150 * @cls: cread state to use for input
151 * @buf: Buffer for input
152 * @entry_save: Buffer to hold vidconsole text-entry information
153 * @sibling: Node to link this scene to its siblings
154 * @obj_head: List of objects in the scene
162 struct cli_line_state cls
;
164 struct abuf entry_save
;
165 struct list_head sibling
;
166 struct list_head obj_head
;
170 * enum scene_obj_t - type of a scene object
172 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
173 * @SCENEOBJT_IMAGE: Image data to render
174 * @SCENEOBJT_TEXT: Text line to render
175 * @SCENEOBJT_MENU: Menu containing items the user can select
176 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
183 /* types from here on can be highlighted */
189 * struct scene_dim - Dimensions of an object
191 * @x: x position, in pixels from left side
192 * @y: y position, in pixels from top
193 * @w: width, in pixels
194 * @h: height, in pixels
204 * enum scene_obj_flags_t - flags for objects
206 * @SCENEOF_HIDE: object should be hidden
207 * @SCENEOF_POINT: object should be highlighted
208 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
211 enum scene_obj_flags_t
{
212 SCENEOF_HIDE
= 1 << 0,
213 SCENEOF_POINT
= 1 << 1,
214 SCENEOF_OPEN
= 1 << 2,
218 /* Maximum number of characters allowed in an line editor */
219 EXPO_MAX_CHARS
= 250,
223 * struct scene_obj - information about an object in a scene
225 * @scene: Scene that this object relates to
226 * @name: Name of the object (allocated)
227 * @id: ID number of the object
228 * @type: Type of this object
229 * @dim: Dimensions for this object
230 * @flags: Flags for this object
231 * @bit_length: Number of bits used for this object in CMOS RAM
232 * @start_bit: Start bit to use for this object in CMOS RAM
233 * @sibling: Node to link this object to its siblings
239 enum scene_obj_t type
;
240 struct scene_dim dim
;
244 struct list_head sibling
;
247 /* object can be highlighted when moving around expo */
248 static inline bool scene_obj_can_highlight(const struct scene_obj
*obj
)
250 return obj
->type
>= SCENEOBJT_MENU
;
254 * struct scene_obj_img - information about an image object in a scene
256 * This is a rectangular image which is blitted onto the display
258 * @obj: Basic object information
259 * @data: Image data in BMP format
261 struct scene_obj_img
{
262 struct scene_obj obj
;
267 * struct scene_obj_txt - information about a text object in a scene
269 * This is a single-line text object
271 * @obj: Basic object information
272 * @str_id: ID of the text string to display
273 * @font_name: Name of font (allocated by caller)
274 * @font_size: Nominal size of font in pixels
276 struct scene_obj_txt
{
277 struct scene_obj obj
;
279 const char *font_name
;
284 * struct scene_obj_menu - information about a menu object in a scene
286 * A menu has a number of items which can be selected by the user
290 * - a text/image object (@pointer_id) which points to the current item
293 * - a preview object which shows an image related to the current item
295 * @obj: Basic object information
296 * @title_id: ID of the title text, or 0 if none
297 * @cur_item_id: ID of the current menu item, or 0 if none
298 * @pointer_id: ID of the object pointing to the current selection
299 * @item_head: List of items in the menu
301 struct scene_obj_menu
{
302 struct scene_obj obj
;
306 struct list_head item_head
;
310 * enum scene_menuitem_flags_t - flags for menu items
312 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
314 enum scene_menuitem_flags_t
{
315 SCENEMIF_GAP_BEFORE
= 1 << 0,
319 * struct scene_menitem - a menu item in a menu
323 * - text object holding the name (short) and description (can be longer)
324 * - a text object holding the keypress
326 * @name: Name of the item (this is allocated by this call)
327 * @id: ID number of the object
328 * @key_id: ID of text object to use as the keypress to show
329 * @label_id: ID of text object to use as the label text
330 * @desc_id: ID of text object to use as the description text
331 * @preview_id: ID of the preview object, or 0 if none
332 * @flags: Flags for this item
333 * @value: Value for this item, or INT_MAX to use sequence
334 * @sibling: Node to link this item to its siblings
336 struct scene_menitem
{
345 struct list_head sibling
;
349 * struct scene_obj_textline - information about a textline in a scene
351 * A textline has a prompt and a line of editable text
353 * @obj: Basic object information
354 * @label_id: ID of the label text, or 0 if none
355 * @edit_id: ID of the editable text
356 * @max_chars: Maximum number of characters allowed
357 * @buf: Text buffer containing current text
358 * @pos: Cursor position
360 struct scene_obj_textline
{
361 struct scene_obj obj
;
370 * struct expo_arrange_info - Information used when arranging a scene
372 * @label_width: Maximum width of labels in scene
374 struct expo_arrange_info
{
379 * expo_new() - create a new expo
381 * Allocates a new expo
383 * @name: Name of expo (this is allocated by this call)
384 * @priv: Private data for the controller
385 * @expp: Returns a pointer to the new expo on success
386 * Returns: 0 if OK, -ENOMEM if out of memory
388 int expo_new(const char *name
, void *priv
, struct expo
**expp
);
391 * expo_destroy() - Destroy an expo and free all its memory
393 * @exp: Expo to destroy
395 void expo_destroy(struct expo
*exp
);
398 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
400 * It is common for a set of 'static' IDs to be used to refer to objects in the
401 * expo. These typically use an enum so that they are defined in sequential
404 * Dynamic IDs (for objects not in the enum) are intended to be used for
405 * objects to which the code does not need to refer. These are ideally located
406 * above the static IDs.
408 * Use this function to set the start of the dynamic range, making sure that the
409 * value is higher than all the statically allocated IDs.
411 * @exp: Expo to update
412 * @dyn_start: Start ID that expo should use for dynamic allocation
414 void expo_set_dynamic_start(struct expo
*exp
, uint dyn_start
);
417 * expo_str() - add a new string to an expo
419 * @exp: Expo to update
420 * @name: Name to use (this is allocated by this call)
421 * @id: ID to use for the new object (0 to allocate one)
422 * @str: Pointer to text to display (allocated by caller)
423 * Returns: ID number for the object (typically @id), or -ve on error
425 int expo_str(struct expo
*exp
, const char *name
, uint id
, const char *str
);
428 * expo_get_str() - Get a string by ID
431 * @id: String ID to look up
432 * @returns string, or NULL if not found
434 const char *expo_get_str(struct expo
*exp
, uint id
);
437 * expo_set_display() - set the display to use for a expo
439 * @exp: Expo to update
440 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
441 * Returns: 0 (always)
443 int expo_set_display(struct expo
*exp
, struct udevice
*dev
);
446 * expo_calc_dims() - Calculate the dimensions of the objects
448 * Updates the width and height of all objects based on their contents
450 * @exp: Expo to update
451 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
453 int expo_calc_dims(struct expo
*exp
);
456 * expo_set_scene_id() - Set the current scene ID
458 * @exp: Expo to update
459 * @scene_id: New scene ID to use (0 to select no scene)
460 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
462 int expo_set_scene_id(struct expo
*exp
, uint scene_id
);
465 * expo_first_scene_id() - Get the ID of the first scene
467 * @exp: Expo to check
468 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
470 int expo_first_scene_id(struct expo
*exp
);
473 * expo_render() - render the expo on the display / console
475 * @exp: Expo to render
477 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
478 * current scene is not found, other error if something else goes wrong
480 int expo_render(struct expo
*exp
);
483 * expo_set_text_mode() - Controls whether the expo renders in text mode
485 * @exp: Expo to update
486 * @text_mode: true to use text mode, false to use the console
488 void expo_set_text_mode(struct expo
*exp
, bool text_mode
);
491 * scene_new() - create a new scene in a expo
493 * The scene is given the ID @id which must be unique across all scenes, objects
494 * and items. The expo's @next_id is updated to at least @id + 1
496 * @exp: Expo to update
497 * @name: Name to use (this is allocated by this call)
498 * @id: ID to use for the new scene (0 to allocate one)
499 * @scnp: Returns a pointer to the new scene on success
500 * Returns: ID number for the scene (typically @id), or -ve on error
502 int scene_new(struct expo
*exp
, const char *name
, uint id
, struct scene
**scnp
);
505 * expo_lookup_scene_id() - Look up a scene by ID
507 * @exp: Expo to check
508 * @scene_id: Scene ID to look up
509 * @returns pointer to scene if found, else NULL
511 struct scene
*expo_lookup_scene_id(struct expo
*exp
, uint scene_id
);
514 * scene_highlight_first() - Highlight the first item in a scene
516 * This highlights the first item, so that the user can see that it is pointed
519 * @scn: Scene to update
521 void scene_highlight_first(struct scene
*scn
);
524 * scene_set_highlight_id() - Set the object which is highlighted
526 * Sets a new object to highlight in the scene
528 * @scn: Scene to update
529 * @id: ID of object to highlight
531 void scene_set_highlight_id(struct scene
*scn
, uint id
);
534 * scene_set_open() - Set whether an item is open or not
536 * @scn: Scene to update
537 * @id: ID of object to update
538 * @open: true to open the object, false to close it
539 * Returns: 0 if OK, -ENOENT if @id is invalid
541 int scene_set_open(struct scene
*scn
, uint id
, bool open
);
544 * scene_obj_count() - Count the number of objects in a scene
546 * @scn: Scene to check
547 * Returns: number of objects in the scene, 0 if none
549 int scene_obj_count(struct scene
*scn
);
552 * scene_img() - add a new image to a scene
554 * @scn: Scene to update
555 * @name: Name to use (this is allocated by this call)
556 * @id: ID to use for the new object (0 to allocate one)
557 * @data: Pointer to image data
558 * @imgp: If non-NULL, returns the new object
559 * Returns: ID number for the object (typically @id), or -ve on error
561 int scene_img(struct scene
*scn
, const char *name
, uint id
, char *data
,
562 struct scene_obj_img
**imgp
);
565 * scene_txt() - add a new text object to a scene
567 * @scn: Scene to update
568 * @name: Name to use (this is allocated by this call)
569 * @id: ID to use for the new object (0 to allocate one)
570 * @str_id: ID of the string to use
571 * @txtp: If non-NULL, returns the new object
572 * Returns: ID number for the object (typically @id), or -ve on error
574 int scene_txt(struct scene
*scn
, const char *name
, uint id
, uint str_id
,
575 struct scene_obj_txt
**txtp
);
578 * scene_txt_str() - add a new string to expo and text object to a scene
580 * @scn: Scene to update
581 * @name: Name to use (this is allocated by this call)
582 * @id: ID to use for the new object (0 to allocate one)
583 * @str_id: ID of the string to use
584 * @str: Pointer to text to display (allocated by caller)
585 * @txtp: If non-NULL, returns the new object
586 * Returns: ID number for the object (typically @id), or -ve on error
588 int scene_txt_str(struct scene
*scn
, const char *name
, uint id
, uint str_id
,
589 const char *str
, struct scene_obj_txt
**txtp
);
592 * scene_menu() - create a menu
594 * @scn: Scene to update
595 * @name: Name to use (this is allocated by this call)
596 * @id: ID to use for the new object (0 to allocate one)
597 * @menup: If non-NULL, returns the new object
598 * Returns: ID number for the object (typically @id), or -ve on error
600 int scene_menu(struct scene
*scn
, const char *name
, uint id
,
601 struct scene_obj_menu
**menup
);
604 * scene_textline() - create a textline
606 * @scn: Scene to update
607 * @name: Name to use (this is allocated by this call)
608 * @id: ID to use for the new object (0 to allocate one)
609 * @max_chars: Maximum length of the textline in characters
610 * @tlinep: If non-NULL, returns the new object
611 * Returns: ID number for the object (typically @id), or -ve on error
613 int scene_textline(struct scene
*scn
, const char *name
, uint id
, uint max_chars
,
614 struct scene_obj_textline
**tlinep
);
617 * scene_txt_set_font() - Set the font for an object
619 * @scn: Scene to update
620 * @id: ID of object to update
621 * @font_name: Font name to use (allocated by caller)
622 * @font_size: Font size to use (nominal height in pixels)
624 int scene_txt_set_font(struct scene
*scn
, uint id
, const char *font_name
,
628 * scene_obj_set_pos() - Set the postion of an object
630 * @scn: Scene to update
631 * @id: ID of object to update
632 * @x: x position, in pixels from left side
633 * @y: y position, in pixels from top
634 * Returns: 0 if OK, -ENOENT if @id is invalid
636 int scene_obj_set_pos(struct scene
*scn
, uint id
, int x
, int y
);
639 * scene_obj_set_size() - Set the size of an object
641 * @scn: Scene to update
642 * @id: ID of object to update
643 * @w: width in pixels
644 * @h: height in pixels
645 * Returns: 0 if OK, -ENOENT if @id is invalid
647 int scene_obj_set_size(struct scene
*scn
, uint id
, int w
, int h
);
650 * scene_obj_set_hide() - Set whether an object is hidden
652 * The update happens when the expo is next rendered.
654 * @scn: Scene to update
655 * @id: ID of object to update
656 * @hide: true to hide the object, false to show it
657 * Returns: 0 if OK, -ENOENT if @id is invalid
659 int scene_obj_set_hide(struct scene
*scn
, uint id
, bool hide
);
662 * scene_menu_set_title() - Set the title of a menu
664 * @scn: Scene to update
665 * @id: ID of menu object to update
666 * @title_id: ID of text object to use as the title
667 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
669 int scene_menu_set_title(struct scene
*scn
, uint id
, uint title_id
);
672 * scene_menu_set_pointer() - Set the item pointer for a menu
674 * This is a visual indicator of the current item, typically a ">" character
675 * which sits next to the current item and moves when the user presses the
678 * @scn: Scene to update
679 * @id: ID of menu object to update
680 * @cur_item_id: ID of text or image object to use as a pointer to the current
682 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
684 int scene_menu_set_pointer(struct scene
*scn
, uint id
, uint cur_item_id
);
687 * scene_obj_get_hw() - Get width and height of an object in a scene
689 * @scn: Scene to check
690 * @id: ID of menu object to check
691 * @widthp: If non-NULL, returns width of object in pixels
692 * Returns: Height of object in pixels
694 int scene_obj_get_hw(struct scene
*scn
, uint id
, int *widthp
);
697 * scene_menuitem() - Add an item to a menu
699 * @scn: Scene to update
700 * @menu_id: ID of menu object to update
701 * @name: Name to use (this is allocated by this call)
702 * @id: ID to use for the new object (0 to allocate one)
703 * @key_id: ID of text object to use as the keypress to show
704 * @label_id: ID of text object to use as the label text
705 * @desc_id: ID of text object to use as the description text
706 * @preview_id: ID of object to use as the preview (text or image)
707 * @flags: Flags for this item (enum scene_menuitem_flags_t)
708 * @itemp: If non-NULL, returns the new object
709 * Returns: ID number for the item (typically @id), or -ve on error
711 int scene_menuitem(struct scene
*scn
, uint menu_id
, const char *name
, uint id
,
712 uint key_id
, uint label_id
, uint desc_id
, uint preview_id
,
713 uint flags
, struct scene_menitem
**itemp
);
716 * scene_arrange() - Arrange the scene to deal with object sizes
718 * Updates any menus in the scene so that their objects are in the right place.
720 * @scn: Scene to arrange
721 * Returns: 0 if OK, -ve on error
723 int scene_arrange(struct scene
*scn
);
726 * expo_send_key() - set a keypress to the expo
728 * @exp: Expo to receive the key
729 * @key: Key to send (ASCII or enum bootmenu_key)
730 * Returns: 0 if OK, -ECHILD if there is no current scene
732 int expo_send_key(struct expo
*exp
, int key
);
735 * expo_action_get() - read user input from the expo
737 * @exp: Expo to check
738 * @act: Returns action
739 * Returns: 0 if OK, -EAGAIN if there was no action to return
741 int expo_action_get(struct expo
*exp
, struct expo_action
*act
);
744 * expo_apply_theme() - Apply a theme to an expo
746 * @exp: Expo to update
747 * @node: Node containing the theme
749 int expo_apply_theme(struct expo
*exp
, ofnode node
);
752 * expo_build() - Build an expo from an FDT description
754 * Build a complete expo from a description in the provided devicetree.
756 * See doc/develop/expo.rst for a description of the format
758 * @root: Root node for expo description
759 * @expp: Returns the new expo
760 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
761 * error, -ENOENT if there is a references to a non-existent string
763 int expo_build(ofnode root
, struct expo
**expp
);
766 * cb_expo_build() - Build an expo for coreboot CMOS RAM
768 * @expp: Returns the expo created
769 * Return: 0 if OK, -ve on error
771 int cb_expo_build(struct expo
**expp
);