memattrs: miscellaneous cleanup to support memattrs binding
v2 cover memattrs: miscellaneous cleanup to support memattrs binding
Hi,
This is my v2. The link to v1 seems to be partially missing [1], and I've also double-checked previous comments from Peter, CLEMENT and Paolo to make sure I haven't lost everyone's feedback :-) (and because of yesterday's little mix-up, I also realized in time that I almost missed Paolo's feedback...).
Introduction
============
This series tries to address the previous comments for memattrs binding [2].
Since bindgen has many limitations on bit fields conversion and it is unable to generate an equivalent macro definition for MEMTXATTRS_UNSPECIFIED, so that memattrs binding requires the external crate to solve many annoyances caused by bit fields.
The easiest way, therefore, is to remove bit fields from memattrs. And that's what this series does.
[1]: https://lore.kernel.org/qemu-devel/[email protected]/T/#m8481b68ec3c38f6281dc96ed77fa376b0bdd1e7e
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
Thanks and Best Regards,
Zhao
---
Zhao Liu (2):
memattrs: Convert unspecified member to bool
memattrs: Check the size of MemTxAttrs
include/exec/memattrs.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 memattrs: Convert unspecified member to bool
Convert unspecified member of MemTxAttrs from bit field to bool, so that bindgen could generate more ergonomic Rust binding with bool type.
As a result, MemTxAttrs needs to be expanded from 4 bytes to 8 bytes.
Therefore, move unspecified to after the bit fields and add reserved members to ensure that the whole structure is packed into 8 bytes.
---
Changes since v1:
* Only convert unspecified to bool, to reserve spare space.
* Mention the size has been changed. (I don't note the spare space since reserved fields are enough.)
--- include/exec/memattrs.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
include/exec/memattrs.h +12 -7
@@ -23,12 +23,6 @@* different semantics. */ typedef struct MemTxAttrs { - /* Bus masters which don't specify any attributes will get this - * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can - * distinguish "all attributes deliberately clear" from - * "didn't specify" if necessary. - */ - unsigned int unspecified:1; /* * ARM/AMBA: TrustZone Secure access * x86: System Management Mode access
@@ -57,6 +51,17 @@ typedef struct MemTxAttrs {* PID (PCI PASID) support: Limited to 8 bits process identifier. */ unsigned int pid:8; + +/* +* Bus masters which don't specify any attributes will get this +* (via the MEMTXATTRS_UNSPECIFIED constant), so that we can +* distinguish "all attributes deliberately clear" from +* "didn't specify" if necessary. +*/ +bool unspecified; + +uint8_t _reserved1; +uint16_t _reserved2; } MemTxAttrs;/* Bus masters which don't specify any attributes will get this,
@@ -64,7 +69,7 @@ typedef struct MemTxAttrs {* (so that we can distinguish "all attributes deliberately clear" * from "didn't specify" if necessary). */ -#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = 1 }) +#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = true })/* New-style MMIO accessors can indicate that the transaction failed. * A zero (MEMTX_OK) response means success; anything else is a failure
Signature · 1 line
2.34.1
PATCH v2 2/2 memattrs: Check the size of MemTxAttrs
In reply to Zhao LiuMake sure MemTxAttrs is packed into 8 bytes and does not exceed 8 bytes.
---
Changes since v1:
* Since MemTxAttrs has been well pakced as 8 bytes, only check if it exceed 8 bytes.
--- include/exec/memattrs.h | 2 ++ 1 file changed, 2 insertions(+)
include/exec/memattrs.h +2 -0
@@ -64,6 +64,8 @@ typedef struct MemTxAttrs {uint16_t _reserved2; } MemTxAttrs; +QEMU_BUILD_BUG_ON (sizeof (MemTxAttrs) >8 ); +/* Bus masters which don't specify any attributes will get this, * which has all attribute bits clear except the topmost one * (so that we can distinguish "all attributes deliberately clear"
Signature · 1 line
2.34.1