blob: 04676a64a591c4d79bde830288ce2b6e9dad2c91 [file] [log] [blame]
Martin Roth4a45ab82019-09-23 18:23:02 -06001/* SPDX-License-Identifier: GPL-2.0-only */
Alexander Couzens77103792015-04-16 02:03:26 +02002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
4#include <acpi/acpigen.h>
Furquan Shaikhc0bff972020-04-30 19:19:33 -07005#include <acpi/acpi_sata.h>
Alexander Couzens77103792015-04-16 02:03:26 +02006
7/* e.g.
8 * generate_sata_ssdt_ports("\_SB.PCI0.SATA", 0x3);
9 * generates:
10 * Scope (\_SB.PCI0.SATA)
11 * {
12 * Device (PR00)
13 * {
14 * Name (_ADR, 0x0000FFFF) // _ADR: Address
15 * }
16 *
17 * Device (PR01)
18 * {
19 * Name (_ADR, 0x0001FFFF) // _ADR: Address
20 * }
21 * }
22 *
23 */
24void generate_sata_ssdt_ports(const char *scope, uint32_t enable_map)
25{
26 int i;
27 uint32_t bit;
28 char port_name[4] = "PR00";
29
30 acpigen_write_scope(scope);
31
32 /* generate a device for every enabled port */
33 for (i = 0; i < 32; i++) {
34 bit = 1 << i;
35 if (!(bit & enable_map))
36 continue;
37
38 port_name[2] = '0' + i / 10;
39 port_name[3] = '0' + i % 10;
40
41 acpigen_write_device(port_name);
42
43 acpigen_write_name_dword("_ADR", 0xffff + i * 0x10000);
44 acpigen_pop_len(); /* close PRT%d */
45 }
46
47 acpigen_pop_len(); /* close scope */
48}