tables.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <malloc.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. /**
  14. * Function prototype to write a specific configuration table
  15. *
  16. * @addr: start address to write the table
  17. * @return: end address of the table
  18. */
  19. typedef ulong (*table_write)(ulong addr);
  20. static table_write table_write_funcs[] = {
  21. #ifdef CONFIG_GENERATE_PIRQ_TABLE
  22. write_pirq_routing_table,
  23. #endif
  24. #ifdef CONFIG_GENERATE_SFI_TABLE
  25. write_sfi_table,
  26. #endif
  27. #ifdef CONFIG_GENERATE_MP_TABLE
  28. write_mp_table,
  29. #endif
  30. #ifdef CONFIG_GENERATE_ACPI_TABLE
  31. write_acpi_tables,
  32. #endif
  33. #ifdef CONFIG_GENERATE_SMBIOS_TABLE
  34. write_smbios_table,
  35. #endif
  36. };
  37. void table_fill_string(char *dest, const char *src, size_t n, char pad)
  38. {
  39. int start, len;
  40. int i;
  41. strncpy(dest, src, n);
  42. /* Fill the remaining bytes with pad */
  43. len = strlen(src);
  44. start = len < n ? len : n;
  45. for (i = start; i < n; i++)
  46. dest[i] = pad;
  47. }
  48. void write_tables(void)
  49. {
  50. u32 rom_table_start = ROM_TABLE_ADDR;
  51. u32 rom_table_end;
  52. #ifdef CONFIG_SEABIOS
  53. u32 high_table, table_size;
  54. struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
  55. #endif
  56. int i;
  57. for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
  58. rom_table_end = table_write_funcs[i](rom_table_start);
  59. rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
  60. #ifdef CONFIG_SEABIOS
  61. table_size = rom_table_end - rom_table_start;
  62. high_table = (u32)high_table_malloc(table_size);
  63. if (high_table) {
  64. table_write_funcs[i](high_table);
  65. cfg_tables[i].start = high_table;
  66. cfg_tables[i].size = table_size;
  67. } else {
  68. printf("%d: no memory for configuration tables\n", i);
  69. }
  70. #endif
  71. rom_table_start = rom_table_end;
  72. }
  73. #ifdef CONFIG_SEABIOS
  74. /* make sure the last item is zero */
  75. cfg_tables[i].size = 0;
  76. write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
  77. #endif
  78. }