tables.c 2.2 KB

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