tables.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  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 u32 (*table_write)(u32 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. u8 table_compute_checksum(void *v, int len)
  37. {
  38. u8 *bytes = v;
  39. u8 checksum = 0;
  40. int i;
  41. for (i = 0; i < len; i++)
  42. checksum -= bytes[i];
  43. return checksum;
  44. }
  45. void table_fill_string(char *dest, const char *src, size_t n, char pad)
  46. {
  47. int start, len;
  48. int i;
  49. strncpy(dest, src, n);
  50. /* Fill the remaining bytes with pad */
  51. len = strlen(src);
  52. start = len < n ? len : n;
  53. for (i = start; i < n; i++)
  54. dest[i] = pad;
  55. }
  56. void write_tables(void)
  57. {
  58. u32 rom_table_start = ROM_TABLE_ADDR;
  59. u32 rom_table_end;
  60. u32 high_table, table_size;
  61. int i;
  62. for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
  63. rom_table_end = table_write_funcs[i](rom_table_start);
  64. rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
  65. table_size = rom_table_end - rom_table_start;
  66. high_table = (u32)memalign(ROM_TABLE_ALIGN, table_size);
  67. if (high_table) {
  68. memset((void *)high_table, 0, table_size);
  69. table_write_funcs[i](high_table);
  70. } else {
  71. printf("%d: no memory for configuration tables\n", i);
  72. }
  73. rom_table_start = rom_table_end;
  74. }
  75. }