tables.c 1.9 KB

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