Martin Roth | 4a45ab8 | 2019-09-23 18:23:02 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Alexander Couzens | 7710379 | 2015-04-16 02:03:26 +0200 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
Furquan Shaikh | c0bff97 | 2020-04-30 19:19:33 -0700 | [diff] [blame] | 5 | #include <acpi/acpi_sata.h> |
Alexander Couzens | 7710379 | 2015-04-16 02:03:26 +0200 | [diff] [blame] | 6 | |
| 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 | */ |
| 24 | void 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 | } |