tables.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <asm/sfi.h>
  8. #include <asm/mpspec.h>
  9. #include <asm/smbios.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 u32 (*table_write)(u32 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. u8 table_compute_checksum(void *v, int len)
  38. {
  39. u8 *bytes = v;
  40. u8 checksum = 0;
  41. int i;
  42. for (i = 0; i < len; i++)
  43. checksum -= bytes[i];
  44. return checksum;
  45. }
  46. void table_fill_string(char *dest, const char *src, size_t n, char pad)
  47. {
  48. int start, len;
  49. int i;
  50. strncpy(dest, src, n);
  51. /* Fill the remaining bytes with pad */
  52. len = strlen(src);
  53. start = len < n ? len : n;
  54. for (i = start; i < n; i++)
  55. dest[i] = pad;
  56. }
  57. void write_tables(void)
  58. {
  59. u32 rom_table_start = ROM_TABLE_ADDR;
  60. u32 rom_table_end;
  61. #ifdef CONFIG_SEABIOS
  62. u32 high_table, table_size;
  63. struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
  64. #endif
  65. int i;
  66. for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
  67. rom_table_end = table_write_funcs[i](rom_table_start);
  68. rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
  69. #ifdef CONFIG_SEABIOS
  70. table_size = rom_table_end - rom_table_start;
  71. high_table = (u32)high_table_malloc(table_size);
  72. if (high_table) {
  73. table_write_funcs[i](high_table);
  74. cfg_tables[i].start = high_table;
  75. cfg_tables[i].size = table_size;
  76. } else {
  77. printf("%d: no memory for configuration tables\n", i);
  78. }
  79. #endif
  80. rom_table_start = rom_table_end;
  81. }
  82. #ifdef CONFIG_SEABIOS
  83. /* make sure the last item is zero */
  84. cfg_tables[i].size = 0;
  85. write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
  86. #endif
  87. }