tables.c 2.0 KB

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