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