[06/14] acpi/srat: add test for Generic Initiator (mantis 1904 for ACPI 6.3)

Message ID 20190208032314.15215-7-alex.hung@canonical.com
State Superseded
Headers show
Series
  • Updates for ACPI 6.2b and 6.3
Related show

Commit Message

Alex Hung Feb. 8, 2019, 3:23 a.m.
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/acpi/srat/srat.c        | 65 +++++++++++++++++++++++++++++++++++++
 src/lib/include/fwts_acpi.h | 11 +++++++
 2 files changed, 76 insertions(+)

Comments

Colin Ian King Feb. 8, 2019, 11:48 a.m. | #1
On 08/02/2019 03:23, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/srat/srat.c        | 65 +++++++++++++++++++++++++++++++++++++
>  src/lib/include/fwts_acpi.h | 11 +++++++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/src/acpi/srat/srat.c b/src/acpi/srat/srat.c
> index 3c37d9ed..edd97903 100644
> --- a/src/acpi/srat/srat.c
> +++ b/src/acpi/srat/srat.c
> @@ -307,6 +307,68 @@ done:
>  	*data += sizeof(fwts_acpi_table_its_affinity);
>  }
>  
> +
> +static void srat_check_initiator_affinity(
> +	fwts_framework *fw,
> +	ssize_t		*length,
> +	uint8_t		**data,
> +	bool		*passed)
> +{
> +	fwts_acpi_table_initiator_affinity *affinity =
> +		(fwts_acpi_table_initiator_affinity *)*data;
> +
> +	if ((ssize_t)sizeof(fwts_acpi_table_initiator_affinity) > *length) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"SRATInitiatorAffinityShort",
> +			"SRAT Initiator Affinity structure too short, got "
> +			"%zu bytes, expecting %zu bytes",
> +			*length, sizeof(fwts_acpi_table_initiator_affinity));
> +		*passed = false;
> +		goto done;
> +	}
> +
> +	if (affinity->length != sizeof(fwts_acpi_table_initiator_affinity)) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"SRATInitiatorAffinityLength",
> +			"SRAT Initiator Affinity Length incorrect, got "
> +			"%" PRIu8 ", expecting %zu",
> +			affinity->length, sizeof(fwts_acpi_table_initiator_affinity));
> +		*passed = false;
> +		goto done;
> +	}
> +
> +	fwts_log_info_verbatim(fw, "SRAT Initiator Affinity Structure:");
> +	fwts_log_info_verbatim(fw, "  Type:                     0x%2.2" PRIx8, affinity->type);
> +	fwts_log_info_verbatim(fw, "  Length:                   0x%2.2" PRIx8, affinity->length);
> +	fwts_log_info_verbatim(fw, "  Reserved:                 0x%2.2" PRIx8, affinity->reserved1);
> +	fwts_log_info_verbatim(fw, "  Device Handle Type:       0x%2.2" PRIx8, affinity->device_handle_type);
> +	fwts_log_info_verbatim(fw, "  Proximity Domain:         0x%8.8" PRIx32, affinity->proximity_domain);
> +	fwts_log_info_verbatim(fw, "  Device Handle:");
> +	if (affinity->device_handle_type == 0) {
> +		fwts_log_info_verbatim(fw, "    ACPI _HID:                0x%16.16" PRIx64, (uint64_t)affinity->device_handle[0]);
> +		fwts_log_info_verbatim(fw, "    ACPI _UID:                0x%8.8" PRIx32, (uint32_t)affinity->device_handle[8]);
> +	} else if (affinity->device_handle_type == 1) {
> +		fwts_log_info_verbatim(fw, "    PCI Segment:              0x%4.4" PRIx16, (uint16_t)affinity->device_handle[0]);
> +		fwts_log_info_verbatim(fw, "    PCI BDF Number:           0x%4.4" PRIx16, (uint16_t)affinity->device_handle[2]);
> +	}
> +	fwts_log_info_verbatim(fw, "  Flags:                    0x%4.4" PRIx16, affinity->flags);
> +	fwts_log_info_verbatim(fw, "  Reserved:                 0x%4.4" PRIx16, affinity->reserved2);
> +	fwts_log_nl(fw);
> +
> +	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved1, sizeof(affinity->reserved1), passed);
> +	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Device Handle Type", affinity->device_handle_type, sizeof(affinity->device_handle_type), 1, 7, passed);
> +	if (affinity->device_handle_type == 0)
> +		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[8], sizeof(uint32_t), passed);
> +	else if (affinity->device_handle_type == 1)
> +		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[4], sizeof(uint64_t), passed);
> +	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Flags", affinity->flags, sizeof(affinity->flags), 1, 15, passed);
> +	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved2, sizeof(affinity->reserved2), passed);
> +
> +done:
> +	*length -= sizeof(fwts_acpi_table_initiator_affinity);
> +	*data += sizeof(fwts_acpi_table_initiator_affinity);
> +}
> +
>  /*
>   *  See ACPI 6.0, Section 5.2.16
>   */
> @@ -345,6 +407,9 @@ static int srat_test1(fwts_framework *fw)
>  		case 0x04:
>  			srat_check_its_affinity(fw, &length, &data, &passed);
>  			break;
> +		case 0x05:
> +			srat_check_initiator_affinity(fw, &length, &data, &passed);
> +			break;
>  		default:
>  			fwts_failed(fw, LOG_LEVEL_HIGH,
>  				"SRATInvalidType",
> diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
> index d03f4c4a..5204744d 100644
> --- a/src/lib/include/fwts_acpi.h
> +++ b/src/lib/include/fwts_acpi.h
> @@ -434,6 +434,17 @@ typedef struct {
>  	uint32_t	its_id;
>  } __attribute__ ((packed)) fwts_acpi_table_its_affinity;
>  
> +typedef struct {
> +	uint8_t		type;
> +	uint8_t		length;
> +	uint8_t		reserved1;
> +	uint8_t		device_handle_type;
> +	uint32_t	proximity_domain;
> +	uint8_t		device_handle[16];
> +	uint32_t	flags;
> +	uint32_t	reserved2;
> +} __attribute__ ((packed)) fwts_acpi_table_initiator_affinity;
> +
>  /*
>   * ACPI HPET (HPET IA-PC High Precision Event Timer Table),
>   *    3.2.4 The ACPI 2.0 HPET Description Table (HPET)
> 
Looks good to me.

Acked-by: Colin Ian King <colin.king@canonical.com>
ivanhu Feb. 18, 2019, 9:30 a.m. | #2
On 2/8/19 11:23 AM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/srat/srat.c        | 65 +++++++++++++++++++++++++++++++++++++
>  src/lib/include/fwts_acpi.h | 11 +++++++
>  2 files changed, 76 insertions(+)
>
> diff --git a/src/acpi/srat/srat.c b/src/acpi/srat/srat.c
> index 3c37d9ed..edd97903 100644
> --- a/src/acpi/srat/srat.c
> +++ b/src/acpi/srat/srat.c
> @@ -307,6 +307,68 @@ done:
>  	*data += sizeof(fwts_acpi_table_its_affinity);
>  }
>  
> +
> +static void srat_check_initiator_affinity(
> +	fwts_framework *fw,
> +	ssize_t		*length,
> +	uint8_t		**data,
> +	bool		*passed)
> +{
> +	fwts_acpi_table_initiator_affinity *affinity =
> +		(fwts_acpi_table_initiator_affinity *)*data;
> +
> +	if ((ssize_t)sizeof(fwts_acpi_table_initiator_affinity) > *length) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"SRATInitiatorAffinityShort",
> +			"SRAT Initiator Affinity structure too short, got "
> +			"%zu bytes, expecting %zu bytes",
> +			*length, sizeof(fwts_acpi_table_initiator_affinity));
> +		*passed = false;
> +		goto done;
> +	}
> +
> +	if (affinity->length != sizeof(fwts_acpi_table_initiator_affinity)) {
> +		fwts_failed(fw, LOG_LEVEL_MEDIUM,
> +			"SRATInitiatorAffinityLength",
> +			"SRAT Initiator Affinity Length incorrect, got "
> +			"%" PRIu8 ", expecting %zu",
> +			affinity->length, sizeof(fwts_acpi_table_initiator_affinity));
> +		*passed = false;
> +		goto done;
> +	}
> +
> +	fwts_log_info_verbatim(fw, "SRAT Initiator Affinity Structure:");
> +	fwts_log_info_verbatim(fw, "  Type:                     0x%2.2" PRIx8, affinity->type);
> +	fwts_log_info_verbatim(fw, "  Length:                   0x%2.2" PRIx8, affinity->length);
> +	fwts_log_info_verbatim(fw, "  Reserved:                 0x%2.2" PRIx8, affinity->reserved1);
> +	fwts_log_info_verbatim(fw, "  Device Handle Type:       0x%2.2" PRIx8, affinity->device_handle_type);
> +	fwts_log_info_verbatim(fw, "  Proximity Domain:         0x%8.8" PRIx32, affinity->proximity_domain);
> +	fwts_log_info_verbatim(fw, "  Device Handle:");
> +	if (affinity->device_handle_type == 0) {
> +		fwts_log_info_verbatim(fw, "    ACPI _HID:                0x%16.16" PRIx64, (uint64_t)affinity->device_handle[0]);
> +		fwts_log_info_verbatim(fw, "    ACPI _UID:                0x%8.8" PRIx32, (uint32_t)affinity->device_handle[8]);
> +	} else if (affinity->device_handle_type == 1) {
> +		fwts_log_info_verbatim(fw, "    PCI Segment:              0x%4.4" PRIx16, (uint16_t)affinity->device_handle[0]);
> +		fwts_log_info_verbatim(fw, "    PCI BDF Number:           0x%4.4" PRIx16, (uint16_t)affinity->device_handle[2]);
> +	}
> +	fwts_log_info_verbatim(fw, "  Flags:                    0x%4.4" PRIx16, affinity->flags);
> +	fwts_log_info_verbatim(fw, "  Reserved:                 0x%4.4" PRIx16, affinity->reserved2);
> +	fwts_log_nl(fw);
> +
> +	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved1, sizeof(affinity->reserved1), passed);
> +	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Device Handle Type", affinity->device_handle_type, sizeof(affinity->device_handle_type), 1, 7, passed);
> +	if (affinity->device_handle_type == 0)
> +		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[8], sizeof(uint32_t), passed);
should

affinity->device_handle[8] be affinity->device_handle[12] ?

please help to check it. 

Ivan

> +	else if (affinity->device_handle_type == 1)
> +		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[4], sizeof(uint64_t), passed);
> +	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Flags", affinity->flags, sizeof(affinity->flags), 1, 15, passed);
> +	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved2, sizeof(affinity->reserved2), passed);
> +
> +done:
> +	*length -= sizeof(fwts_acpi_table_initiator_affinity);
> +	*data += sizeof(fwts_acpi_table_initiator_affinity);
> +}
> +
>  /*
>   *  See ACPI 6.0, Section 5.2.16
>   */
> @@ -345,6 +407,9 @@ static int srat_test1(fwts_framework *fw)
>  		case 0x04:
>  			srat_check_its_affinity(fw, &length, &data, &passed);
>  			break;
> +		case 0x05:
> +			srat_check_initiator_affinity(fw, &length, &data, &passed);
> +			break;
>  		default:
>  			fwts_failed(fw, LOG_LEVEL_HIGH,
>  				"SRATInvalidType",
> diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
> index d03f4c4a..5204744d 100644
> --- a/src/lib/include/fwts_acpi.h
> +++ b/src/lib/include/fwts_acpi.h
> @@ -434,6 +434,17 @@ typedef struct {
>  	uint32_t	its_id;
>  } __attribute__ ((packed)) fwts_acpi_table_its_affinity;
>  
> +typedef struct {
> +	uint8_t		type;
> +	uint8_t		length;
> +	uint8_t		reserved1;
> +	uint8_t		device_handle_type;
> +	uint32_t	proximity_domain;
> +	uint8_t		device_handle[16];
> +	uint32_t	flags;
> +	uint32_t	reserved2;
> +} __attribute__ ((packed)) fwts_acpi_table_initiator_affinity;
> +
>  /*
>   * ACPI HPET (HPET IA-PC High Precision Event Timer Table),
>   *    3.2.4 The ACPI 2.0 HPET Description Table (HPET)

Patch

diff --git a/src/acpi/srat/srat.c b/src/acpi/srat/srat.c
index 3c37d9ed..edd97903 100644
--- a/src/acpi/srat/srat.c
+++ b/src/acpi/srat/srat.c
@@ -307,6 +307,68 @@  done:
 	*data += sizeof(fwts_acpi_table_its_affinity);
 }
 
+
+static void srat_check_initiator_affinity(
+	fwts_framework *fw,
+	ssize_t		*length,
+	uint8_t		**data,
+	bool		*passed)
+{
+	fwts_acpi_table_initiator_affinity *affinity =
+		(fwts_acpi_table_initiator_affinity *)*data;
+
+	if ((ssize_t)sizeof(fwts_acpi_table_initiator_affinity) > *length) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"SRATInitiatorAffinityShort",
+			"SRAT Initiator Affinity structure too short, got "
+			"%zu bytes, expecting %zu bytes",
+			*length, sizeof(fwts_acpi_table_initiator_affinity));
+		*passed = false;
+		goto done;
+	}
+
+	if (affinity->length != sizeof(fwts_acpi_table_initiator_affinity)) {
+		fwts_failed(fw, LOG_LEVEL_MEDIUM,
+			"SRATInitiatorAffinityLength",
+			"SRAT Initiator Affinity Length incorrect, got "
+			"%" PRIu8 ", expecting %zu",
+			affinity->length, sizeof(fwts_acpi_table_initiator_affinity));
+		*passed = false;
+		goto done;
+	}
+
+	fwts_log_info_verbatim(fw, "SRAT Initiator Affinity Structure:");
+	fwts_log_info_verbatim(fw, "  Type:                     0x%2.2" PRIx8, affinity->type);
+	fwts_log_info_verbatim(fw, "  Length:                   0x%2.2" PRIx8, affinity->length);
+	fwts_log_info_verbatim(fw, "  Reserved:                 0x%2.2" PRIx8, affinity->reserved1);
+	fwts_log_info_verbatim(fw, "  Device Handle Type:       0x%2.2" PRIx8, affinity->device_handle_type);
+	fwts_log_info_verbatim(fw, "  Proximity Domain:         0x%8.8" PRIx32, affinity->proximity_domain);
+	fwts_log_info_verbatim(fw, "  Device Handle:");
+	if (affinity->device_handle_type == 0) {
+		fwts_log_info_verbatim(fw, "    ACPI _HID:                0x%16.16" PRIx64, (uint64_t)affinity->device_handle[0]);
+		fwts_log_info_verbatim(fw, "    ACPI _UID:                0x%8.8" PRIx32, (uint32_t)affinity->device_handle[8]);
+	} else if (affinity->device_handle_type == 1) {
+		fwts_log_info_verbatim(fw, "    PCI Segment:              0x%4.4" PRIx16, (uint16_t)affinity->device_handle[0]);
+		fwts_log_info_verbatim(fw, "    PCI BDF Number:           0x%4.4" PRIx16, (uint16_t)affinity->device_handle[2]);
+	}
+	fwts_log_info_verbatim(fw, "  Flags:                    0x%4.4" PRIx16, affinity->flags);
+	fwts_log_info_verbatim(fw, "  Reserved:                 0x%4.4" PRIx16, affinity->reserved2);
+	fwts_log_nl(fw);
+
+	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved1, sizeof(affinity->reserved1), passed);
+	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Device Handle Type", affinity->device_handle_type, sizeof(affinity->device_handle_type), 1, 7, passed);
+	if (affinity->device_handle_type == 0)
+		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[8], sizeof(uint32_t), passed);
+	else if (affinity->device_handle_type == 1)
+		fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Device Handle Reserve", affinity->device_handle[4], sizeof(uint64_t), passed);
+	fwts_acpi_reserved_bits_check(fw, "SRAT", "Initiator Affinity Flags", affinity->flags, sizeof(affinity->flags), 1, 15, passed);
+	fwts_acpi_reserved_zero_check(fw, "SRAT", "Initiator Affinity Reserved", affinity->reserved2, sizeof(affinity->reserved2), passed);
+
+done:
+	*length -= sizeof(fwts_acpi_table_initiator_affinity);
+	*data += sizeof(fwts_acpi_table_initiator_affinity);
+}
+
 /*
  *  See ACPI 6.0, Section 5.2.16
  */
@@ -345,6 +407,9 @@  static int srat_test1(fwts_framework *fw)
 		case 0x04:
 			srat_check_its_affinity(fw, &length, &data, &passed);
 			break;
+		case 0x05:
+			srat_check_initiator_affinity(fw, &length, &data, &passed);
+			break;
 		default:
 			fwts_failed(fw, LOG_LEVEL_HIGH,
 				"SRATInvalidType",
diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
index d03f4c4a..5204744d 100644
--- a/src/lib/include/fwts_acpi.h
+++ b/src/lib/include/fwts_acpi.h
@@ -434,6 +434,17 @@  typedef struct {
 	uint32_t	its_id;
 } __attribute__ ((packed)) fwts_acpi_table_its_affinity;
 
+typedef struct {
+	uint8_t		type;
+	uint8_t		length;
+	uint8_t		reserved1;
+	uint8_t		device_handle_type;
+	uint32_t	proximity_domain;
+	uint8_t		device_handle[16];
+	uint32_t	flags;
+	uint32_t	reserved2;
+} __attribute__ ((packed)) fwts_acpi_table_initiator_affinity;
+
 /*
  * ACPI HPET (HPET IA-PC High Precision Event Timer Table),
  *    3.2.4 The ACPI 2.0 HPET Description Table (HPET)