18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Name: acbuffer.h - Support for buffers returned by ACPI predefined names
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2000 - 2020, Intel Corp.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *****************************************************************************/
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __ACBUFFER_H__
118c2ecf20Sopenharmony_ci#define __ACBUFFER_H__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * Contains buffer structures for these predefined names:
158c2ecf20Sopenharmony_ci * _FDE, _GRT, _GTM, _PLD, _SRT
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/*
198c2ecf20Sopenharmony_ci * Note: C bitfields are not used for this reason:
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * "Bitfields are great and easy to read, but unfortunately the C language
228c2ecf20Sopenharmony_ci * does not specify the layout of bitfields in memory, which means they are
238c2ecf20Sopenharmony_ci * essentially useless for dealing with packed data in on-disk formats or
248c2ecf20Sopenharmony_ci * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
258c2ecf20Sopenharmony_ci * this decision was a design error in C. Ritchie could have picked an order
268c2ecf20Sopenharmony_ci * and stuck with it." Norman Ramsey.
278c2ecf20Sopenharmony_ci * See http://stackoverflow.com/a/1053662/41661
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* _FDE return value */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct acpi_fde_info {
338c2ecf20Sopenharmony_ci	u32 floppy0;
348c2ecf20Sopenharmony_ci	u32 floppy1;
358c2ecf20Sopenharmony_ci	u32 floppy2;
368c2ecf20Sopenharmony_ci	u32 floppy3;
378c2ecf20Sopenharmony_ci	u32 tape;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/*
418c2ecf20Sopenharmony_ci * _GRT return value
428c2ecf20Sopenharmony_ci * _SRT input value
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_cistruct acpi_grt_info {
458c2ecf20Sopenharmony_ci	u16 year;
468c2ecf20Sopenharmony_ci	u8 month;
478c2ecf20Sopenharmony_ci	u8 day;
488c2ecf20Sopenharmony_ci	u8 hour;
498c2ecf20Sopenharmony_ci	u8 minute;
508c2ecf20Sopenharmony_ci	u8 second;
518c2ecf20Sopenharmony_ci	u8 valid;
528c2ecf20Sopenharmony_ci	u16 milliseconds;
538c2ecf20Sopenharmony_ci	u16 timezone;
548c2ecf20Sopenharmony_ci	u8 daylight;
558c2ecf20Sopenharmony_ci	u8 reserved[3];
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* _GTM return value */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct acpi_gtm_info {
618c2ecf20Sopenharmony_ci	u32 pio_speed0;
628c2ecf20Sopenharmony_ci	u32 dma_speed0;
638c2ecf20Sopenharmony_ci	u32 pio_speed1;
648c2ecf20Sopenharmony_ci	u32 dma_speed1;
658c2ecf20Sopenharmony_ci	u32 flags;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/*
698c2ecf20Sopenharmony_ci * Formatted _PLD return value. The minimum size is a package containing
708c2ecf20Sopenharmony_ci * one buffer.
718c2ecf20Sopenharmony_ci * Revision 1: Buffer is 16 bytes (128 bits)
728c2ecf20Sopenharmony_ci * Revision 2: Buffer is 20 bytes (160 bits)
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * Note: This structure is returned from the acpi_decode_pld_buffer
758c2ecf20Sopenharmony_ci * interface.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_cistruct acpi_pld_info {
788c2ecf20Sopenharmony_ci	u8 revision;
798c2ecf20Sopenharmony_ci	u8 ignore_color;
808c2ecf20Sopenharmony_ci	u8 red;
818c2ecf20Sopenharmony_ci	u8 green;
828c2ecf20Sopenharmony_ci	u8 blue;
838c2ecf20Sopenharmony_ci	u16 width;
848c2ecf20Sopenharmony_ci	u16 height;
858c2ecf20Sopenharmony_ci	u8 user_visible;
868c2ecf20Sopenharmony_ci	u8 dock;
878c2ecf20Sopenharmony_ci	u8 lid;
888c2ecf20Sopenharmony_ci	u8 panel;
898c2ecf20Sopenharmony_ci	u8 vertical_position;
908c2ecf20Sopenharmony_ci	u8 horizontal_position;
918c2ecf20Sopenharmony_ci	u8 shape;
928c2ecf20Sopenharmony_ci	u8 group_orientation;
938c2ecf20Sopenharmony_ci	u8 group_token;
948c2ecf20Sopenharmony_ci	u8 group_position;
958c2ecf20Sopenharmony_ci	u8 bay;
968c2ecf20Sopenharmony_ci	u8 ejectable;
978c2ecf20Sopenharmony_ci	u8 ospm_eject_required;
988c2ecf20Sopenharmony_ci	u8 cabinet_number;
998c2ecf20Sopenharmony_ci	u8 card_cage_number;
1008c2ecf20Sopenharmony_ci	u8 reference;
1018c2ecf20Sopenharmony_ci	u8 rotation;
1028c2ecf20Sopenharmony_ci	u8 order;
1038c2ecf20Sopenharmony_ci	u8 reserved;
1048c2ecf20Sopenharmony_ci	u16 vertical_offset;
1058c2ecf20Sopenharmony_ci	u16 horizontal_offset;
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/*
1098c2ecf20Sopenharmony_ci * Macros to:
1108c2ecf20Sopenharmony_ci *     1) Convert a _PLD buffer to internal struct acpi_pld_info format - ACPI_PLD_GET*
1118c2ecf20Sopenharmony_ci *        (Used by acpi_decode_pld_buffer)
1128c2ecf20Sopenharmony_ci *     2) Construct a _PLD buffer - ACPI_PLD_SET*
1138c2ecf20Sopenharmony_ci *        (Intended for BIOS use only)
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_ci#define ACPI_PLD_REV1_BUFFER_SIZE               16	/* For Revision 1 of the buffer (From ACPI spec) */
1168c2ecf20Sopenharmony_ci#define ACPI_PLD_REV2_BUFFER_SIZE               20	/* For Revision 2 of the buffer (From ACPI spec) */
1178c2ecf20Sopenharmony_ci#define ACPI_PLD_BUFFER_SIZE                    20	/* For Revision 2 of the buffer (From ACPI spec) */
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* First 32-bit dword, bits 0:32 */
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_REVISION(dword)            ACPI_GET_BITS (dword, 0, ACPI_7BIT_MASK)
1228c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_REVISION(dword,value)      ACPI_SET_BITS (dword, 0, ACPI_7BIT_MASK, value)	/* Offset 0, Len 7 */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_IGNORE_COLOR(dword)        ACPI_GET_BITS (dword, 7, ACPI_1BIT_MASK)
1258c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_IGNORE_COLOR(dword,value)  ACPI_SET_BITS (dword, 7, ACPI_1BIT_MASK, value)	/* Offset 7, Len 1 */
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_RED(dword)                 ACPI_GET_BITS (dword, 8, ACPI_8BIT_MASK)
1288c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_RED(dword,value)           ACPI_SET_BITS (dword, 8, ACPI_8BIT_MASK, value)	/* Offset 8, Len 8 */
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_GREEN(dword)               ACPI_GET_BITS (dword, 16, ACPI_8BIT_MASK)
1318c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_GREEN(dword,value)         ACPI_SET_BITS (dword, 16, ACPI_8BIT_MASK, value)	/* Offset 16, Len 8 */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_BLUE(dword)                ACPI_GET_BITS (dword, 24, ACPI_8BIT_MASK)
1348c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_BLUE(dword,value)          ACPI_SET_BITS (dword, 24, ACPI_8BIT_MASK, value)	/* Offset 24, Len 8 */
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* Second 32-bit dword, bits 33:63 */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_WIDTH(dword)               ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
1398c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_WIDTH(dword,value)         ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)	/* Offset 32+0=32, Len 16 */
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_HEIGHT(dword)              ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
1428c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_HEIGHT(dword,value)        ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 32+16=48, Len 16 */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/* Third 32-bit dword, bits 64:95 */
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_USER_VISIBLE(dword)        ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
1478c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_USER_VISIBLE(dword,value)  ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)	/* Offset 64+0=64, Len 1 */
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_DOCK(dword)                ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
1508c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_DOCK(dword,value)          ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)	/* Offset 64+1=65, Len 1 */
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_LID(dword)                 ACPI_GET_BITS (dword, 2, ACPI_1BIT_MASK)
1538c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_LID(dword,value)           ACPI_SET_BITS (dword, 2, ACPI_1BIT_MASK, value)	/* Offset 64+2=66, Len 1 */
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_PANEL(dword)               ACPI_GET_BITS (dword, 3, ACPI_3BIT_MASK)
1568c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_PANEL(dword,value)         ACPI_SET_BITS (dword, 3, ACPI_3BIT_MASK, value)	/* Offset 64+3=67, Len 3 */
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_VERTICAL(dword)            ACPI_GET_BITS (dword, 6, ACPI_2BIT_MASK)
1598c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_VERTICAL(dword,value)      ACPI_SET_BITS (dword, 6, ACPI_2BIT_MASK, value)	/* Offset 64+6=70, Len 2 */
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_HORIZONTAL(dword)          ACPI_GET_BITS (dword, 8, ACPI_2BIT_MASK)
1628c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_HORIZONTAL(dword,value)    ACPI_SET_BITS (dword, 8, ACPI_2BIT_MASK, value)	/* Offset 64+8=72, Len 2 */
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_SHAPE(dword)               ACPI_GET_BITS (dword, 10, ACPI_4BIT_MASK)
1658c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_SHAPE(dword,value)         ACPI_SET_BITS (dword, 10, ACPI_4BIT_MASK, value)	/* Offset 64+10=74, Len 4 */
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_ORIENTATION(dword)         ACPI_GET_BITS (dword, 14, ACPI_1BIT_MASK)
1688c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_ORIENTATION(dword,value)   ACPI_SET_BITS (dword, 14, ACPI_1BIT_MASK, value)	/* Offset 64+14=78, Len 1 */
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_TOKEN(dword)               ACPI_GET_BITS (dword, 15, ACPI_8BIT_MASK)
1718c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_TOKEN(dword,value)         ACPI_SET_BITS (dword, 15, ACPI_8BIT_MASK, value)	/* Offset 64+15=79, Len 8 */
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_POSITION(dword)            ACPI_GET_BITS (dword, 23, ACPI_8BIT_MASK)
1748c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_POSITION(dword,value)      ACPI_SET_BITS (dword, 23, ACPI_8BIT_MASK, value)	/* Offset 64+23=87, Len 8 */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_BAY(dword)                 ACPI_GET_BITS (dword, 31, ACPI_1BIT_MASK)
1778c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_BAY(dword,value)           ACPI_SET_BITS (dword, 31, ACPI_1BIT_MASK, value)	/* Offset 64+31=95, Len 1 */
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* Fourth 32-bit dword, bits 96:127 */
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_EJECTABLE(dword)           ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
1828c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_EJECTABLE(dword,value)     ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)	/* Offset 96+0=96, Len 1 */
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_OSPM_EJECT(dword)          ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
1858c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_OSPM_EJECT(dword,value)    ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)	/* Offset 96+1=97, Len 1 */
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_CABINET(dword)             ACPI_GET_BITS (dword, 2, ACPI_8BIT_MASK)
1888c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_CABINET(dword,value)       ACPI_SET_BITS (dword, 2, ACPI_8BIT_MASK, value)	/* Offset 96+2=98, Len 8 */
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_CARD_CAGE(dword)           ACPI_GET_BITS (dword, 10, ACPI_8BIT_MASK)
1918c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_CARD_CAGE(dword,value)     ACPI_SET_BITS (dword, 10, ACPI_8BIT_MASK, value)	/* Offset 96+10=106, Len 8 */
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_REFERENCE(dword)           ACPI_GET_BITS (dword, 18, ACPI_1BIT_MASK)
1948c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_REFERENCE(dword,value)     ACPI_SET_BITS (dword, 18, ACPI_1BIT_MASK, value)	/* Offset 96+18=114, Len 1 */
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_ROTATION(dword)            ACPI_GET_BITS (dword, 19, ACPI_4BIT_MASK)
1978c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_ROTATION(dword,value)      ACPI_SET_BITS (dword, 19, ACPI_4BIT_MASK, value)	/* Offset 96+19=115, Len 4 */
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_ORDER(dword)               ACPI_GET_BITS (dword, 23, ACPI_5BIT_MASK)
2008c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_ORDER(dword,value)         ACPI_SET_BITS (dword, 23, ACPI_5BIT_MASK, value)	/* Offset 96+23=119, Len 5 */
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci/* Fifth 32-bit dword, bits 128:159 (Revision 2 of _PLD only) */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_VERT_OFFSET(dword)         ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
2058c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_VERT_OFFSET(dword,value)   ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)	/* Offset 128+0=128, Len 16 */
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
2088c2ecf20Sopenharmony_ci#define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 128+16=144, Len 16 */
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#endif				/* ACBUFFER_H */
211