[1/3] lib: fwts_acpi_tables: add a new function to check reserved bits

Message ID 1504861633-20512-1-git-send-email-alex.hung@canonical.com
State Accepted
Headers show
Series
  • [1/3] lib: fwts_acpi_tables: add a new function to check reserved bits
Related show

Commit Message

Alex Hung Sept. 8, 2017, 9:07 a.m.
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/lib/include/fwts_acpi_tables.h |  1 +
 src/lib/src/fwts_acpi_tables.c     | 52 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

Comments

ivanhu Sept. 22, 2017, 8:49 a.m. | #1
On 09/08/2017 05:07 PM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>   src/lib/include/fwts_acpi_tables.h |  1 +
>   src/lib/src/fwts_acpi_tables.c     | 52 ++++++++++++++++++++++++++++++++++++++
>   2 files changed, 53 insertions(+)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index d478d99..011a4c3 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -54,6 +54,7 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
>   fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
>   
>   void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
> +void fwts_acpi_reserved_bits_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, uint8_t min, uint8_t max, bool *passed);
>   
>   #endif
>   
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 4ac70f8..15d07f4 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -1426,4 +1426,56 @@ void fwts_acpi_reserved_zero_check(
>   	}
>   }
>   
> +/*
> + *  fwts_acpi_reserved_bits_check()
> + *  verify whether the reserved bits are zero
> + */
> +void fwts_acpi_reserved_bits_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	const char *field,
> +	uint64_t value,
> +	uint8_t size,
> +	uint8_t min,
> +	uint8_t max,
> +	bool *passed)
> +{
> +	uint64_t mask = 0;
> +	uint8_t i;
> +
> +	for (i = min; i <= max; i++) {
> +		mask |= (1ULL << i);
> +	}
> +
> +	if (value & mask) {
> +		char label[24];
> +		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
> +		strncpy(label + 4, "ReservedBitsNonZero", sizeof(label) - 4);
> +
> +		switch (size) {
> +		case sizeof(uint8_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%2.2" PRIx8 " instead", table, field, max, min, (uint8_t)value);
> +			break;
> +		case sizeof(uint16_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%4.4" PRIx16 " instead", table, field, max, min, (uint16_t)value);
> +			break;
> +		case sizeof(uint32_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%8.8" PRIx32 " instead", table, field, max, min, (uint32_t)value);
> +			break;
> +		case sizeof(uint64_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%16.16" PRIx64 " instead", table, field, max, min, value);
> +			break;
> +		}
> +		*passed = false;
> +	}
> +}
> +
>   #endif
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Colin King Sept. 25, 2017, noon | #2
On 08/09/17 10:07, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/lib/include/fwts_acpi_tables.h |  1 +
>  src/lib/src/fwts_acpi_tables.c     | 52 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 53 insertions(+)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index d478d99..011a4c3 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -54,6 +54,7 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
>  fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
>  
>  void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
> +void fwts_acpi_reserved_bits_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, uint8_t min, uint8_t max, bool *passed);
>  
>  #endif
>  
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 4ac70f8..15d07f4 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -1426,4 +1426,56 @@ void fwts_acpi_reserved_zero_check(
>  	}
>  }
>  
> +/*
> + *  fwts_acpi_reserved_bits_check()
> + *  verify whether the reserved bits are zero
> + */
> +void fwts_acpi_reserved_bits_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	const char *field,
> +	uint64_t value,
> +	uint8_t size,
> +	uint8_t min,
> +	uint8_t max,
> +	bool *passed)
> +{
> +	uint64_t mask = 0;
> +	uint8_t i;
> +
> +	for (i = min; i <= max; i++) {
> +		mask |= (1ULL << i);
> +	}
> +
> +	if (value & mask) {
> +		char label[24];
> +		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
> +		strncpy(label + 4, "ReservedBitsNonZero", sizeof(label) - 4);
> +
> +		switch (size) {
> +		case sizeof(uint8_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%2.2" PRIx8 " instead", table, field, max, min, (uint8_t)value);
> +			break;
> +		case sizeof(uint16_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%4.4" PRIx16 " instead", table, field, max, min, (uint16_t)value);
> +			break;
> +		case sizeof(uint32_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%8.8" PRIx32 " instead", table, field, max, min, (uint32_t)value);
> +			break;
> +		case sizeof(uint64_t):
> +			fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
> +				"0x%16.16" PRIx64 " instead", table, field, max, min, value);
> +			break;
> +		}
> +		*passed = false;
> +	}
> +}
> +
>  #endif
> 

Acked-by: Colin Ian King <colin.king@canonical.com>

Patch

diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
index d478d99..011a4c3 100644
--- a/src/lib/include/fwts_acpi_tables.h
+++ b/src/lib/include/fwts_acpi_tables.h
@@ -54,6 +54,7 @@  bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
 fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
 
 void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
+void fwts_acpi_reserved_bits_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, uint8_t min, uint8_t max, bool *passed);
 
 #endif
 
diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 4ac70f8..15d07f4 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -1426,4 +1426,56 @@  void fwts_acpi_reserved_zero_check(
 	}
 }
 
+/*
+ *  fwts_acpi_reserved_bits_check()
+ *  verify whether the reserved bits are zero
+ */
+void fwts_acpi_reserved_bits_check(
+	fwts_framework *fw,
+	const char *table,
+	const char *field,
+	uint64_t value,
+	uint8_t size,
+	uint8_t min,
+	uint8_t max,
+	bool *passed)
+{
+	uint64_t mask = 0;
+	uint8_t i;
+
+	for (i = min; i <= max; i++) {
+		mask |= (1ULL << i);
+	}
+
+	if (value & mask) {
+		char label[24];
+		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
+		strncpy(label + 4, "ReservedBitsNonZero", sizeof(label) - 4);
+
+		switch (size) {
+		case sizeof(uint8_t):
+			fwts_failed(fw, LOG_LEVEL_HIGH, label,
+				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
+				"0x%2.2" PRIx8 " instead", table, field, max, min, (uint8_t)value);
+			break;
+		case sizeof(uint16_t):
+			fwts_failed(fw, LOG_LEVEL_HIGH, label,
+				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
+				"0x%4.4" PRIx16 " instead", table, field, max, min, (uint16_t)value);
+			break;
+		case sizeof(uint32_t):
+			fwts_failed(fw, LOG_LEVEL_HIGH, label,
+				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
+				"0x%8.8" PRIx32 " instead", table, field, max, min, (uint32_t)value);
+			break;
+		case sizeof(uint64_t):
+			fwts_failed(fw, LOG_LEVEL_HIGH, label,
+				"%4.4s %s Bits [%" PRIu8 "..%" PRIu8 "] must be zero, got "
+				"0x%16.16" PRIx64 " instead", table, field, max, min, value);
+			break;
+		}
+		*passed = false;
+	}
+}
+
 #endif