coreboot_table.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * coreboot_table.h
  4. *
  5. * Internal header for coreboot table access.
  6. *
  7. * Copyright 2014 Gerd Hoffmann <kraxel@redhat.com>
  8. * Copyright 2017 Google Inc.
  9. * Copyright 2017 Samuel Holland <samuel@sholland.org>
  10. */
  11. #ifndef __COREBOOT_TABLE_H
  12. #define __COREBOOT_TABLE_H
  13. #include <linux/device.h>
  14. #include <linux/mod_devicetable.h>
  15. /* Coreboot table header structure */
  16. struct coreboot_table_header {
  17. char signature[4];
  18. u32 header_bytes;
  19. u32 header_checksum;
  20. u32 table_bytes;
  21. u32 table_checksum;
  22. u32 table_entries;
  23. };
  24. /* List of coreboot entry structures that is used */
  25. /* Generic */
  26. struct coreboot_table_entry {
  27. u32 tag;
  28. u32 size;
  29. };
  30. /* Points to a CBMEM entry */
  31. struct lb_cbmem_ref {
  32. u32 tag;
  33. u32 size;
  34. u64 cbmem_addr;
  35. };
  36. #define LB_TAG_CBMEM_ENTRY 0x31
  37. /* Corresponds to LB_TAG_CBMEM_ENTRY */
  38. struct lb_cbmem_entry {
  39. u32 tag;
  40. u32 size;
  41. u64 address;
  42. u32 entry_size;
  43. u32 id;
  44. };
  45. /* Describes framebuffer setup by coreboot */
  46. struct lb_framebuffer {
  47. u32 tag;
  48. u32 size;
  49. u64 physical_address;
  50. u32 x_resolution;
  51. u32 y_resolution;
  52. u32 bytes_per_line;
  53. u8 bits_per_pixel;
  54. u8 red_mask_pos;
  55. u8 red_mask_size;
  56. u8 green_mask_pos;
  57. u8 green_mask_size;
  58. u8 blue_mask_pos;
  59. u8 blue_mask_size;
  60. u8 reserved_mask_pos;
  61. u8 reserved_mask_size;
  62. };
  63. /* A device, additionally with information from coreboot. */
  64. struct coreboot_device {
  65. struct device dev;
  66. union {
  67. struct coreboot_table_entry entry;
  68. struct lb_cbmem_ref cbmem_ref;
  69. struct lb_cbmem_entry cbmem_entry;
  70. struct lb_framebuffer framebuffer;
  71. DECLARE_FLEX_ARRAY(u8, raw);
  72. };
  73. };
  74. static inline struct coreboot_device *dev_to_coreboot_device(struct device *dev)
  75. {
  76. return container_of(dev, struct coreboot_device, dev);
  77. }
  78. /* A driver for handling devices described in coreboot tables. */
  79. struct coreboot_driver {
  80. int (*probe)(struct coreboot_device *);
  81. void (*remove)(struct coreboot_device *);
  82. struct device_driver drv;
  83. const struct coreboot_device_id *id_table;
  84. };
  85. /* use a macro to avoid include chaining to get THIS_MODULE */
  86. #define coreboot_driver_register(driver) \
  87. __coreboot_driver_register(driver, THIS_MODULE)
  88. /* Register a driver that uses the data from a coreboot table. */
  89. int __coreboot_driver_register(struct coreboot_driver *driver,
  90. struct module *owner);
  91. /* Unregister a driver that uses the data from a coreboot table. */
  92. void coreboot_driver_unregister(struct coreboot_driver *driver);
  93. /* module_coreboot_driver() - Helper macro for drivers that don't do
  94. * anything special in module init/exit. This eliminates a lot of
  95. * boilerplate. Each module may only use this macro once, and
  96. * calling it replaces module_init() and module_exit()
  97. */
  98. #define module_coreboot_driver(__coreboot_driver) \
  99. module_driver(__coreboot_driver, coreboot_driver_register, \
  100. coreboot_driver_unregister)
  101. #endif /* __COREBOOT_TABLE_H */