From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Cc: patches@linaro.org
Subject: [Qemu-trivial] [PATCH 6/6] bswap.h: Document cpu_to_* and *_to_cpu conversion functions
Date: Tue, 28 Jun 2016 15:50:51 +0100 [thread overview]
Message-ID: <1467125451-16700-7-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1467125451-16700-1-git-send-email-peter.maydell@linaro.org>
Add a documentation comment describing the functions for
converting between the cpu and little or bigendian formats.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
include/qemu/bswap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index a17d9aa..be3233a 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -80,6 +80,64 @@ static inline void bswap64s(uint64_t *s)
#define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
#endif
+/**
+ * Endianness conversion functions between host cpu and specified endianness.
+ * (We list the complete set of prototypes produced by the macros below
+ * to assist people who search the headers to find their definitions.)
+ *
+ * uint16_t le16_to_cpu(uint16_t v);
+ * uint32_t le32_to_cpu(uint32_t v);
+ * uint64_t le64_to_cpu(uint64_t v);
+ * uint16_t be16_to_cpu(uint16_t v);
+ * uint32_t be32_to_cpu(uint32_t v);
+ * uint64_t be64_to_cpu(uint64_t v);
+ *
+ * Convert the value @v from the specified format to the native
+ * endianness of the host CPU by byteswapping if necessary, and
+ * return the converted value.
+ *
+ * uint16_t cpu_to_le16(uint16_t v);
+ * uint32_t cpu_to_le32(uint32_t v);
+ * uint64_t cpu_to_le64(uint64_t v);
+ * uint16_t cpu_to_be16(uint16_t v);
+ * uint32_t cpu_to_be32(uint32_t v);
+ * uint64_t cpu_to_be64(uint64_t v);
+ *
+ * Convert the value @v from the native endianness of the host CPU to
+ * the specified format by byteswapping if necessary, and return
+ * the converted value.
+ *
+ * uint16_t le16_to_cpus(uint16_t *v);
+ * uint32_t le32_to_cpus(uint32_t *v);
+ * uint64_t le64_to_cpus(uint64_t *v);
+ * uint16_t be16_to_cpus(uint16_t *v);
+ * uint32_t be32_to_cpus(uint32_t *v);
+ * uint64_t be64_to_cpus(uint64_t *v);
+ *
+ * Do an in-place conversion of the value pointed to by @v from the
+ * specified format to the native endianness of the host CPU.
+ *
+ * uint16_t cpu_to_le16s(uint16_t *v);
+ * uint32_t cpu_to_le32s(uint32_t *v);
+ * uint64_t cpu_to_le64s(uint64_t *v);
+ * uint16_t cpu_to_be16s(uint16_t *v);
+ * uint32_t cpu_to_be32s(uint32_t *v);
+ * uint64_t cpu_to_be64s(uint64_t *v);
+ *
+ * Do an in-place conversion of the value pointed to by @v from the
+ * native endianness of the host CPU to the specified format.
+ *
+ * Both X_to_cpu() and cpu_to_X() perform the same operation; you
+ * should use whichever one is better documenting of the function your
+ * code is performing.
+ *
+ * Do not use these functions for conversion of values which are in guest
+ * memory, since the data may not be sufficiently aligned for the host CPU's
+ * load and store instructions. Instead you should use the ld*_p() and
+ * st*_p() functions, which perform loads and stores of data of any
+ * required size and endianness and handle possible misalignment.
+ */
+
#define CPU_CONVERT(endian, size, type)\
static inline type endian ## size ## _to_cpu(type v)\
{\
--
1.9.1
next prev parent reply other threads:[~2016-06-28 14:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-28 14:50 [Qemu-trivial] [PATCH 0/6] Drop cpu_to_*w, *_to_cpup, document cpu_to_*, *_to_cpu Peter Maydell
2016-06-28 14:50 ` [Qemu-trivial] [PATCH 1/6] fsdev/9p-iov-marshal.c: Don't use cpu_to_*w() functions Peter Maydell
2016-06-28 15:09 ` [Qemu-trivial] [Qemu-devel] " Eric Blake
2016-06-28 14:50 ` [Qemu-trivial] [PATCH 2/6] block/qcow2: Don't use cpu_to_*w() Peter Maydell
2016-06-28 15:13 ` [Qemu-trivial] [Qemu-devel] " Eric Blake
2016-06-28 15:13 ` Peter Maydell
2016-06-28 14:50 ` [Qemu-trivial] [PATCH 3/6] hw/bt: Don't use cpu_to_*w() and *_to_cpup() Peter Maydell
2016-06-28 15:27 ` [Qemu-trivial] [Qemu-devel] " Eric Blake
2016-06-28 14:50 ` [Qemu-trivial] [PATCH 4/6] bswap.h: Remove unused " Peter Maydell
2016-06-28 15:38 ` [Qemu-trivial] [Qemu-devel] " Eric Blake
2016-06-28 14:50 ` [Qemu-trivial] [PATCH 5/6] bswap.h: Fix comment typo Peter Maydell
2016-06-28 15:05 ` [Qemu-trivial] [Qemu-devel] " Stefan Weil
2016-06-28 14:50 ` Peter Maydell [this message]
2016-06-28 14:58 ` [Qemu-trivial] [Qemu-devel] [PATCH 6/6] bswap.h: Document cpu_to_* and *_to_cpu conversion functions Peter Maydell
2016-06-28 15:40 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467125451-16700-7-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=patches@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).