162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
262306a36Sopenharmony_ci/******************************************************************************
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Name: acbuffer.h - Support for buffers returned by ACPI predefined names
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2000 - 2023, Intel Corp.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci *****************************************************************************/
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __ACBUFFER_H__
1162306a36Sopenharmony_ci#define __ACBUFFER_H__
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * Contains buffer structures for these predefined names:
1562306a36Sopenharmony_ci * _FDE, _GRT, _GTM, _PLD, _SRT
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/*
1962306a36Sopenharmony_ci * Note: C bitfields are not used for this reason:
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * "Bitfields are great and easy to read, but unfortunately the C language
2262306a36Sopenharmony_ci * does not specify the layout of bitfields in memory, which means they are
2362306a36Sopenharmony_ci * essentially useless for dealing with packed data in on-disk formats or
2462306a36Sopenharmony_ci * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
2562306a36Sopenharmony_ci * this decision was a design error in C. Ritchie could have picked an order
2662306a36Sopenharmony_ci * and stuck with it." Norman Ramsey.
2762306a36Sopenharmony_ci * See http://stackoverflow.com/a/1053662/41661
2862306a36Sopenharmony_ci */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* _FDE return value */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistruct acpi_fde_info {
3362306a36Sopenharmony_ci	u32 floppy0;
3462306a36Sopenharmony_ci	u32 floppy1;
3562306a36Sopenharmony_ci	u32 floppy2;
3662306a36Sopenharmony_ci	u32 floppy3;
3762306a36Sopenharmony_ci	u32 tape;
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/*
4162306a36Sopenharmony_ci * _GRT return value
4262306a36Sopenharmony_ci * _SRT input value
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_cistruct acpi_grt_info {
4562306a36Sopenharmony_ci	u16 year;
4662306a36Sopenharmony_ci	u8 month;
4762306a36Sopenharmony_ci	u8 day;
4862306a36Sopenharmony_ci	u8 hour;
4962306a36Sopenharmony_ci	u8 minute;
5062306a36Sopenharmony_ci	u8 second;
5162306a36Sopenharmony_ci	u8 valid;
5262306a36Sopenharmony_ci	u16 milliseconds;
5362306a36Sopenharmony_ci	u16 timezone;
5462306a36Sopenharmony_ci	u8 daylight;
5562306a36Sopenharmony_ci	u8 reserved[3];
5662306a36Sopenharmony_ci};
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* _GTM return value */
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct acpi_gtm_info {
6162306a36Sopenharmony_ci	u32 pio_speed0;
6262306a36Sopenharmony_ci	u32 dma_speed0;
6362306a36Sopenharmony_ci	u32 pio_speed1;
6462306a36Sopenharmony_ci	u32 dma_speed1;
6562306a36Sopenharmony_ci	u32 flags;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/*
6962306a36Sopenharmony_ci * Formatted _PLD return value. The minimum size is a package containing
7062306a36Sopenharmony_ci * one buffer.
7162306a36Sopenharmony_ci * Revision 1: Buffer is 16 bytes (128 bits)
7262306a36Sopenharmony_ci * Revision 2: Buffer is 20 bytes (160 bits)
7362306a36Sopenharmony_ci *
7462306a36Sopenharmony_ci * Note: This structure is returned from the acpi_decode_pld_buffer
7562306a36Sopenharmony_ci * interface.
7662306a36Sopenharmony_ci */
7762306a36Sopenharmony_cistruct acpi_pld_info {
7862306a36Sopenharmony_ci	u8 revision;
7962306a36Sopenharmony_ci	u8 ignore_color;
8062306a36Sopenharmony_ci	u8 red;
8162306a36Sopenharmony_ci	u8 green;
8262306a36Sopenharmony_ci	u8 blue;
8362306a36Sopenharmony_ci	u16 width;
8462306a36Sopenharmony_ci	u16 height;
8562306a36Sopenharmony_ci	u8 user_visible;
8662306a36Sopenharmony_ci	u8 dock;
8762306a36Sopenharmony_ci	u8 lid;
8862306a36Sopenharmony_ci	u8 panel;
8962306a36Sopenharmony_ci	u8 vertical_position;
9062306a36Sopenharmony_ci	u8 horizontal_position;
9162306a36Sopenharmony_ci	u8 shape;
9262306a36Sopenharmony_ci	u8 group_orientation;
9362306a36Sopenharmony_ci	u8 group_token;
9462306a36Sopenharmony_ci	u8 group_position;
9562306a36Sopenharmony_ci	u8 bay;
9662306a36Sopenharmony_ci	u8 ejectable;
9762306a36Sopenharmony_ci	u8 ospm_eject_required;
9862306a36Sopenharmony_ci	u8 cabinet_number;
9962306a36Sopenharmony_ci	u8 card_cage_number;
10062306a36Sopenharmony_ci	u8 reference;
10162306a36Sopenharmony_ci	u8 rotation;
10262306a36Sopenharmony_ci	u8 order;
10362306a36Sopenharmony_ci	u8 reserved;
10462306a36Sopenharmony_ci	u16 vertical_offset;
10562306a36Sopenharmony_ci	u16 horizontal_offset;
10662306a36Sopenharmony_ci};
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/*
10962306a36Sopenharmony_ci * Macros to:
11062306a36Sopenharmony_ci *     1) Convert a _PLD buffer to internal struct acpi_pld_info format - ACPI_PLD_GET*
11162306a36Sopenharmony_ci *        (Used by acpi_decode_pld_buffer)
11262306a36Sopenharmony_ci *     2) Construct a _PLD buffer - ACPI_PLD_SET*
11362306a36Sopenharmony_ci *        (Intended for BIOS use only)
11462306a36Sopenharmony_ci */
11562306a36Sopenharmony_ci#define ACPI_PLD_REV1_BUFFER_SIZE               16	/* For Revision 1 of the buffer (From ACPI spec) */
11662306a36Sopenharmony_ci#define ACPI_PLD_REV2_BUFFER_SIZE               20	/* For Revision 2 of the buffer (From ACPI spec) */
11762306a36Sopenharmony_ci#define ACPI_PLD_BUFFER_SIZE                    20	/* For Revision 2 of the buffer (From ACPI spec) */
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci/* First 32-bit dword, bits 0:32 */
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define ACPI_PLD_GET_REVISION(dword)            ACPI_GET_BITS (dword, 0, ACPI_7BIT_MASK)
12262306a36Sopenharmony_ci#define ACPI_PLD_SET_REVISION(dword,value)      ACPI_SET_BITS (dword, 0, ACPI_7BIT_MASK, value)	/* Offset 0, Len 7 */
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define ACPI_PLD_GET_IGNORE_COLOR(dword)        ACPI_GET_BITS (dword, 7, ACPI_1BIT_MASK)
12562306a36Sopenharmony_ci#define ACPI_PLD_SET_IGNORE_COLOR(dword,value)  ACPI_SET_BITS (dword, 7, ACPI_1BIT_MASK, value)	/* Offset 7, Len 1 */
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci#define ACPI_PLD_GET_RED(dword)                 ACPI_GET_BITS (dword, 8, ACPI_8BIT_MASK)
12862306a36Sopenharmony_ci#define ACPI_PLD_SET_RED(dword,value)           ACPI_SET_BITS (dword, 8, ACPI_8BIT_MASK, value)	/* Offset 8, Len 8 */
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define ACPI_PLD_GET_GREEN(dword)               ACPI_GET_BITS (dword, 16, ACPI_8BIT_MASK)
13162306a36Sopenharmony_ci#define ACPI_PLD_SET_GREEN(dword,value)         ACPI_SET_BITS (dword, 16, ACPI_8BIT_MASK, value)	/* Offset 16, Len 8 */
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define ACPI_PLD_GET_BLUE(dword)                ACPI_GET_BITS (dword, 24, ACPI_8BIT_MASK)
13462306a36Sopenharmony_ci#define ACPI_PLD_SET_BLUE(dword,value)          ACPI_SET_BITS (dword, 24, ACPI_8BIT_MASK, value)	/* Offset 24, Len 8 */
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* Second 32-bit dword, bits 33:63 */
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define ACPI_PLD_GET_WIDTH(dword)               ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
13962306a36Sopenharmony_ci#define ACPI_PLD_SET_WIDTH(dword,value)         ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)	/* Offset 32+0=32, Len 16 */
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci#define ACPI_PLD_GET_HEIGHT(dword)              ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
14262306a36Sopenharmony_ci#define ACPI_PLD_SET_HEIGHT(dword,value)        ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 32+16=48, Len 16 */
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* Third 32-bit dword, bits 64:95 */
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci#define ACPI_PLD_GET_USER_VISIBLE(dword)        ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
14762306a36Sopenharmony_ci#define ACPI_PLD_SET_USER_VISIBLE(dword,value)  ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)	/* Offset 64+0=64, Len 1 */
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#define ACPI_PLD_GET_DOCK(dword)                ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
15062306a36Sopenharmony_ci#define ACPI_PLD_SET_DOCK(dword,value)          ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)	/* Offset 64+1=65, Len 1 */
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci#define ACPI_PLD_GET_LID(dword)                 ACPI_GET_BITS (dword, 2, ACPI_1BIT_MASK)
15362306a36Sopenharmony_ci#define ACPI_PLD_SET_LID(dword,value)           ACPI_SET_BITS (dword, 2, ACPI_1BIT_MASK, value)	/* Offset 64+2=66, Len 1 */
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci#define ACPI_PLD_GET_PANEL(dword)               ACPI_GET_BITS (dword, 3, ACPI_3BIT_MASK)
15662306a36Sopenharmony_ci#define ACPI_PLD_SET_PANEL(dword,value)         ACPI_SET_BITS (dword, 3, ACPI_3BIT_MASK, value)	/* Offset 64+3=67, Len 3 */
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci#define ACPI_PLD_GET_VERTICAL(dword)            ACPI_GET_BITS (dword, 6, ACPI_2BIT_MASK)
15962306a36Sopenharmony_ci#define ACPI_PLD_SET_VERTICAL(dword,value)      ACPI_SET_BITS (dword, 6, ACPI_2BIT_MASK, value)	/* Offset 64+6=70, Len 2 */
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#define ACPI_PLD_GET_HORIZONTAL(dword)          ACPI_GET_BITS (dword, 8, ACPI_2BIT_MASK)
16262306a36Sopenharmony_ci#define ACPI_PLD_SET_HORIZONTAL(dword,value)    ACPI_SET_BITS (dword, 8, ACPI_2BIT_MASK, value)	/* Offset 64+8=72, Len 2 */
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#define ACPI_PLD_GET_SHAPE(dword)               ACPI_GET_BITS (dword, 10, ACPI_4BIT_MASK)
16562306a36Sopenharmony_ci#define ACPI_PLD_SET_SHAPE(dword,value)         ACPI_SET_BITS (dword, 10, ACPI_4BIT_MASK, value)	/* Offset 64+10=74, Len 4 */
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define ACPI_PLD_GET_ORIENTATION(dword)         ACPI_GET_BITS (dword, 14, ACPI_1BIT_MASK)
16862306a36Sopenharmony_ci#define ACPI_PLD_SET_ORIENTATION(dword,value)   ACPI_SET_BITS (dword, 14, ACPI_1BIT_MASK, value)	/* Offset 64+14=78, Len 1 */
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci#define ACPI_PLD_GET_TOKEN(dword)               ACPI_GET_BITS (dword, 15, ACPI_8BIT_MASK)
17162306a36Sopenharmony_ci#define ACPI_PLD_SET_TOKEN(dword,value)         ACPI_SET_BITS (dword, 15, ACPI_8BIT_MASK, value)	/* Offset 64+15=79, Len 8 */
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define ACPI_PLD_GET_POSITION(dword)            ACPI_GET_BITS (dword, 23, ACPI_8BIT_MASK)
17462306a36Sopenharmony_ci#define ACPI_PLD_SET_POSITION(dword,value)      ACPI_SET_BITS (dword, 23, ACPI_8BIT_MASK, value)	/* Offset 64+23=87, Len 8 */
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci#define ACPI_PLD_GET_BAY(dword)                 ACPI_GET_BITS (dword, 31, ACPI_1BIT_MASK)
17762306a36Sopenharmony_ci#define ACPI_PLD_SET_BAY(dword,value)           ACPI_SET_BITS (dword, 31, ACPI_1BIT_MASK, value)	/* Offset 64+31=95, Len 1 */
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/* Fourth 32-bit dword, bits 96:127 */
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci#define ACPI_PLD_GET_EJECTABLE(dword)           ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
18262306a36Sopenharmony_ci#define ACPI_PLD_SET_EJECTABLE(dword,value)     ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)	/* Offset 96+0=96, Len 1 */
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci#define ACPI_PLD_GET_OSPM_EJECT(dword)          ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
18562306a36Sopenharmony_ci#define ACPI_PLD_SET_OSPM_EJECT(dword,value)    ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)	/* Offset 96+1=97, Len 1 */
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci#define ACPI_PLD_GET_CABINET(dword)             ACPI_GET_BITS (dword, 2, ACPI_8BIT_MASK)
18862306a36Sopenharmony_ci#define ACPI_PLD_SET_CABINET(dword,value)       ACPI_SET_BITS (dword, 2, ACPI_8BIT_MASK, value)	/* Offset 96+2=98, Len 8 */
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define ACPI_PLD_GET_CARD_CAGE(dword)           ACPI_GET_BITS (dword, 10, ACPI_8BIT_MASK)
19162306a36Sopenharmony_ci#define ACPI_PLD_SET_CARD_CAGE(dword,value)     ACPI_SET_BITS (dword, 10, ACPI_8BIT_MASK, value)	/* Offset 96+10=106, Len 8 */
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#define ACPI_PLD_GET_REFERENCE(dword)           ACPI_GET_BITS (dword, 18, ACPI_1BIT_MASK)
19462306a36Sopenharmony_ci#define ACPI_PLD_SET_REFERENCE(dword,value)     ACPI_SET_BITS (dword, 18, ACPI_1BIT_MASK, value)	/* Offset 96+18=114, Len 1 */
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci#define ACPI_PLD_GET_ROTATION(dword)            ACPI_GET_BITS (dword, 19, ACPI_4BIT_MASK)
19762306a36Sopenharmony_ci#define ACPI_PLD_SET_ROTATION(dword,value)      ACPI_SET_BITS (dword, 19, ACPI_4BIT_MASK, value)	/* Offset 96+19=115, Len 4 */
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#define ACPI_PLD_GET_ORDER(dword)               ACPI_GET_BITS (dword, 23, ACPI_5BIT_MASK)
20062306a36Sopenharmony_ci#define ACPI_PLD_SET_ORDER(dword,value)         ACPI_SET_BITS (dword, 23, ACPI_5BIT_MASK, value)	/* Offset 96+23=119, Len 5 */
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci/* Fifth 32-bit dword, bits 128:159 (Revision 2 of _PLD only) */
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci#define ACPI_PLD_GET_VERT_OFFSET(dword)         ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
20562306a36Sopenharmony_ci#define ACPI_PLD_SET_VERT_OFFSET(dword,value)   ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)	/* Offset 128+0=128, Len 16 */
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci#define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
20862306a36Sopenharmony_ci#define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 128+16=144, Len 16 */
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci/* Panel position defined in _PLD section of ACPI Specification 6.3 */
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#define ACPI_PLD_PANEL_TOP      0
21362306a36Sopenharmony_ci#define ACPI_PLD_PANEL_BOTTOM   1
21462306a36Sopenharmony_ci#define ACPI_PLD_PANEL_LEFT     2
21562306a36Sopenharmony_ci#define ACPI_PLD_PANEL_RIGHT    3
21662306a36Sopenharmony_ci#define ACPI_PLD_PANEL_FRONT    4
21762306a36Sopenharmony_ci#define ACPI_PLD_PANEL_BACK     5
21862306a36Sopenharmony_ci#define ACPI_PLD_PANEL_UNKNOWN  6
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci#endif				/* ACBUFFER_H */
221