tables.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <log.h>
  7. #include <malloc.h>
  8. #include <smbios.h>
  9. #include <acpi/acpi_table.h>
  10. #include <asm/sfi.h>
  11. #include <asm/mpspec.h>
  12. #include <asm/tables.h>
  13. #include <asm/coreboot_tables.h>
  14. /**
  15. * Function prototype to write a specific configuration table
  16. *
  17. * @addr: start address to write the table
  18. * @return: end address of the table
  19. */
  20. typedef ulong (*table_write)(ulong addr);
  21. /**
  22. * struct table_info - Information about each table to write
  23. *
  24. * @name: Name of table (for debugging)
  25. * @write: Function to call to write this table
  26. */
  27. struct table_info {
  28. const char *name;
  29. table_write write;
  30. };
  31. static struct table_info table_list[] = {
  32. #ifdef CONFIG_GENERATE_PIRQ_TABLE
  33. { "pirq", write_pirq_routing_table },
  34. #endif
  35. #ifdef CONFIG_GENERATE_SFI_TABLE
  36. { "sfi", write_sfi_table, },
  37. #endif
  38. #ifdef CONFIG_GENERATE_MP_TABLE
  39. { "mp", write_mp_table, },
  40. #endif
  41. #ifdef CONFIG_GENERATE_ACPI_TABLE
  42. { "acpi", write_acpi_tables, },
  43. #endif
  44. #ifdef CONFIG_GENERATE_SMBIOS_TABLE
  45. { "smbios", write_smbios_table, },
  46. #endif
  47. };
  48. void table_fill_string(char *dest, const char *src, size_t n, char pad)
  49. {
  50. int start, len;
  51. int i;
  52. strncpy(dest, src, n);
  53. /* Fill the remaining bytes with pad */
  54. len = strlen(src);
  55. start = len < n ? len : n;
  56. for (i = start; i < n; i++)
  57. dest[i] = pad;
  58. }
  59. void write_tables(void)
  60. {
  61. u32 rom_table_start = ROM_TABLE_ADDR;
  62. u32 rom_table_end;
  63. #ifdef CONFIG_SEABIOS
  64. u32 high_table, table_size;
  65. struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1];
  66. #endif
  67. int i;
  68. debug("Writing tables to %x:\n", rom_table_start);
  69. for (i = 0; i < ARRAY_SIZE(table_list); i++) {
  70. const struct table_info *table = &table_list[i];
  71. rom_table_end = table->write(rom_table_start);
  72. rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
  73. #ifdef CONFIG_SEABIOS
  74. table_size = rom_table_end - rom_table_start;
  75. high_table = (u32)high_table_malloc(table_size);
  76. if (high_table) {
  77. table->write(high_table);
  78. cfg_tables[i].start = high_table;
  79. cfg_tables[i].size = table_size;
  80. } else {
  81. printf("%d: no memory for configuration tables\n", i);
  82. }
  83. #endif
  84. debug("- wrote '%s' to %x, end %x\n", table->name,
  85. rom_table_start, rom_table_end);
  86. rom_table_start = rom_table_end;
  87. }
  88. #ifdef CONFIG_SEABIOS
  89. /* make sure the last item is zero */
  90. cfg_tables[i].size = 0;
  91. write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
  92. #endif
  93. debug("- done writing tables\n");
  94. }