tables.c 2.1 KB

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