blob: e7b8abd55690ee9d79710758b85592ff83c60698 [file] [log] [blame]
Simon Glass2d67fdf2020-04-08 16:57:34 -06001// 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 Glassb2672ea2020-04-08 16:57:38 -060011#include <acpi/acpi_table.h>
Simon Glass2d67fdf2020-04-08 16:57:34 -060012#include <dm/acpi.h>
13#include <dm/test.h>
14#include <test/ut.h>
15
16#define ACPI_TEST_DEV_NAME "ABCD"
17
18static 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
23struct acpi_ops testacpi_ops = {
24 .get_name = testacpi_get_name,
25};
26
27static const struct udevice_id testacpi_ids[] = {
28 { .compatible = "denx,u-boot-acpi-test" },
29 { }
30};
31
32U_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
39UCLASS_DRIVER(testacpi) = {
40 .name = "testacpi",
41 .id = UCLASS_TEST_ACPI,
42};
43
44/* Test ACPI get_name() */
45static 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}
56DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Simon Glassb2672ea2020-04-08 16:57:38 -060057
58/* Test acpi_get_table_revision() */
59static 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}
68DM_TEST(dm_test_acpi_get_table_revision,
69 DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Simon Glasse9629892020-04-08 16:57:39 -060070
71/* Temporary change to ensure bisectability */
72#ifndef CONFIG_SANDBOX
73/* Test acpi_create_dmar() */
74static 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}
84DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
85#endif