Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Tests for ACPI table generation |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 11 | #include <acpi/acpi_table.h> |
Simon Glass | 2d67fdf | 2020-04-08 16:57:34 -0600 | [diff] [blame] | 12 | #include <dm/acpi.h> |
| 13 | #include <dm/test.h> |
| 14 | #include <test/ut.h> |
| 15 | |
| 16 | #define ACPI_TEST_DEV_NAME "ABCD" |
| 17 | |
| 18 | static int testacpi_get_name(const struct udevice *dev, char *out_name) |
| 19 | { |
| 20 | return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME); |
| 21 | } |
| 22 | |
| 23 | struct acpi_ops testacpi_ops = { |
| 24 | .get_name = testacpi_get_name, |
| 25 | }; |
| 26 | |
| 27 | static const struct udevice_id testacpi_ids[] = { |
| 28 | { .compatible = "denx,u-boot-acpi-test" }, |
| 29 | { } |
| 30 | }; |
| 31 | |
| 32 | U_BOOT_DRIVER(testacpi_drv) = { |
| 33 | .name = "testacpi_drv", |
| 34 | .of_match = testacpi_ids, |
| 35 | .id = UCLASS_TEST_ACPI, |
| 36 | ACPI_OPS_PTR(&testacpi_ops) |
| 37 | }; |
| 38 | |
| 39 | UCLASS_DRIVER(testacpi) = { |
| 40 | .name = "testacpi", |
| 41 | .id = UCLASS_TEST_ACPI, |
| 42 | }; |
| 43 | |
| 44 | /* Test ACPI get_name() */ |
| 45 | static int dm_test_acpi_get_name(struct unit_test_state *uts) |
| 46 | { |
| 47 | char name[ACPI_NAME_MAX]; |
| 48 | struct udevice *dev; |
| 49 | |
| 50 | ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); |
| 51 | ut_assertok(acpi_get_name(dev, name)); |
| 52 | ut_asserteq_str(ACPI_TEST_DEV_NAME, name); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | b2672ea | 2020-04-08 16:57:38 -0600 | [diff] [blame] | 57 | |
| 58 | /* Test acpi_get_table_revision() */ |
| 59 | static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) |
| 60 | { |
| 61 | ut_asserteq(1, acpi_get_table_revision(ACPITAB_MCFG)); |
| 62 | ut_asserteq(2, acpi_get_table_revision(ACPITAB_RSDP)); |
| 63 | ut_asserteq(4, acpi_get_table_revision(ACPITAB_TPM2)); |
| 64 | ut_asserteq(-EINVAL, acpi_get_table_revision(ACPITAB_COUNT)); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | DM_TEST(dm_test_acpi_get_table_revision, |
| 69 | DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | e962989 | 2020-04-08 16:57:39 -0600 | [diff] [blame] | 70 | |
| 71 | /* Temporary change to ensure bisectability */ |
| 72 | #ifndef CONFIG_SANDBOX |
| 73 | /* Test acpi_create_dmar() */ |
| 74 | static int dm_test_acpi_create_dmar(struct unit_test_state *uts) |
| 75 | { |
| 76 | struct acpi_dmar dmar; |
| 77 | |
| 78 | ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP)); |
| 79 | ut_asserteq(DMAR_INTR_REMAP, dmar.flags); |
| 80 | ut_asserteq(32 - 1, dmar.host_address_width); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 85 | #endif |