acpi.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2017 Intel Corporation
  4. *
  5. * Partially based on acpi.c for other x86 platforms
  6. */
  7. #include <common.h>
  8. #include <cpu.h>
  9. #include <dm.h>
  10. #include <acpi/acpi_table.h>
  11. #include <asm/ioapic.h>
  12. #include <asm/mpspec.h>
  13. #include <asm/tables.h>
  14. #include <asm/arch/global_nvs.h>
  15. #include <asm/arch/iomap.h>
  16. #include <dm/uclass-internal.h>
  17. void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
  18. void *dsdt)
  19. {
  20. struct acpi_table_header *header = &(fadt->header);
  21. memset((void *)fadt, 0, sizeof(struct acpi_fadt));
  22. acpi_fill_header(header, "FACP");
  23. header->length = sizeof(struct acpi_fadt);
  24. header->revision = 6;
  25. fadt->firmware_ctrl = (u32)facs;
  26. fadt->dsdt = (u32)dsdt;
  27. fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
  28. fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
  29. ACPI_FADT_NO_PCIE_ASPM_CONTROL;
  30. fadt->flags =
  31. ACPI_FADT_WBINVD |
  32. ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
  33. ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
  34. ACPI_FADT_HW_REDUCED_ACPI;
  35. fadt->minor_revision = 2;
  36. fadt->x_firmware_ctl_l = (u32)facs;
  37. fadt->x_firmware_ctl_h = 0;
  38. fadt->x_dsdt_l = (u32)dsdt;
  39. fadt->x_dsdt_h = 0;
  40. header->checksum = table_compute_checksum(fadt, header->length);
  41. }
  42. u32 acpi_fill_madt(u32 current)
  43. {
  44. current += acpi_create_madt_lapics(current);
  45. current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
  46. io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
  47. return current;
  48. }
  49. u32 acpi_fill_mcfg(u32 current)
  50. {
  51. /* TODO: Derive parameters from SFI MCFG table */
  52. current += acpi_create_mcfg_mmconfig
  53. ((struct acpi_mcfg_mmconfig *)current,
  54. MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
  55. return current;
  56. }
  57. static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
  58. {
  59. struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
  60. /* Fill the Resource Group with Shared Information attached */
  61. memset(grp, 0, sizeof(*grp));
  62. grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
  63. grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
  64. /* TODO: All values below should come from U-Boot DT somehow */
  65. sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
  66. grp->device_id = 0x11a2;
  67. /* Fill the Resource Group Shared Information */
  68. memset(si, 0, sizeof(*si));
  69. si->major_version = 1;
  70. si->minor_version = 0;
  71. /* TODO: All values below should come from U-Boot DT somehow */
  72. si->mmio_base_low = 0xff192000;
  73. si->mmio_base_high = 0;
  74. si->gsi_interrupt = 32;
  75. si->interrupt_polarity = 0; /* Active High */
  76. si->interrupt_mode = 0; /* Level triggered */
  77. si->num_channels = 8;
  78. si->dma_address_width = 32;
  79. si->base_request_line = 0;
  80. si->num_handshake_signals = 16;
  81. si->max_block_size = 0x1ffff;
  82. return grp->length;
  83. }
  84. u32 acpi_fill_csrt(u32 current)
  85. {
  86. current += acpi_fill_csrt_dma((struct acpi_csrt_group *)current);
  87. return current;
  88. }
  89. int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
  90. {
  91. struct udevice *dev;
  92. int ret;
  93. /* at least we have one processor */
  94. gnvs->pcnt = 1;
  95. /* override the processor count with actual number */
  96. ret = uclass_find_first_device(UCLASS_CPU, &dev);
  97. if (ret == 0 && dev != NULL) {
  98. ret = cpu_get_count(dev);
  99. if (ret > 0)
  100. gnvs->pcnt = ret;
  101. }
  102. return 0;
  103. }