From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <rth@twiddle.net>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/4] exec: Support 64-bit operations in address_space_rw
Date: Sun, 14 Jul 2013 08:38:36 +0200 [thread overview]
Message-ID: <51E2476C.20207@redhat.com> (raw)
In-Reply-To: <1373331672-19852-4-git-send-email-rth@twiddle.net>
Il 09/07/2013 03:01, Richard Henderson ha scritto:
> Honor the implementation maximum access size, and at least check
> the minimum access size.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
> exec.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
> 1 file changed, 56 insertions(+), 12 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 03fdf7e..5da22dc 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1902,15 +1902,37 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
> return false;
> }
>
> -static inline int memory_access_size(MemoryRegion *mr, int l, hwaddr addr)
> +static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
> {
> - if (l >= 4 && (((addr & 3) == 0 || mr->ops->impl.unaligned))) {
> - return 4;
> + unsigned access_size_min = mr->ops->impl.min_access_size;
> + unsigned access_size_max = mr->ops->impl.max_access_size;
> +
> + /* Regions are assumed to support 1-4 byte accesses unless
> + otherwise specified. */
> + if (access_size_min == 0) {
> + access_size_min = 1;
> + }
> + if (access_size_max == 0) {
> + access_size_max = 4;
> + }
> +
> + /* Bound the maximum access by the alignment of the address. */
> + if (!mr->ops->impl.unaligned) {
> + unsigned align_size_max = addr & -addr;
> + if (align_size_max != 0 && align_size_max < access_size_max) {
> + access_size_max = align_size_max;
> + }
> }
> - if (l >= 2 && (((addr & 1) == 0) || mr->ops->impl.unaligned)) {
> - return 2;
> +
> + /* Don't attempt accesses larger than the maximum. */
> + if (l > access_size_max) {
> + l = access_size_max;
> }
> - return 1;
> + /* ??? The users of this function are wrong, not supporting minimums larger
> + than the remaining length. C.f. memory.c:access_with_adjusted_size. */
> + assert(l >= access_size_min);
> +
> + return l;
> }
>
> bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
> @@ -1932,18 +1954,29 @@ bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
> l = memory_access_size(mr, l, addr1);
> /* XXX: could force cpu_single_env to NULL to avoid
> potential bugs */
> - if (l == 4) {
> + switch (l) {
> + case 8:
> + /* 64 bit write access */
> + val = ldq_p(buf);
> + error |= io_mem_write(mr, addr1, val, 8);
> + break;
> + case 4:
> /* 32 bit write access */
> val = ldl_p(buf);
> error |= io_mem_write(mr, addr1, val, 4);
> - } else if (l == 2) {
> + break;
> + case 2:
> /* 16 bit write access */
> val = lduw_p(buf);
> error |= io_mem_write(mr, addr1, val, 2);
> - } else {
> + break;
> + case 1:
> /* 8 bit write access */
> val = ldub_p(buf);
> error |= io_mem_write(mr, addr1, val, 1);
> + break;
> + default:
> + abort();
> }
> } else {
> addr1 += memory_region_get_ram_addr(mr);
> @@ -1956,18 +1989,29 @@ bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
> if (!memory_access_is_direct(mr, is_write)) {
> /* I/O case */
> l = memory_access_size(mr, l, addr1);
> - if (l == 4) {
> + switch (l) {
> + case 8:
> + /* 64 bit read access */
> + error |= io_mem_read(mr, addr1, &val, 8);
> + stq_p(buf, val);
> + break;
> + case 4:
> /* 32 bit read access */
> error |= io_mem_read(mr, addr1, &val, 4);
> stl_p(buf, val);
> - } else if (l == 2) {
> + break;
> + case 2:
> /* 16 bit read access */
> error |= io_mem_read(mr, addr1, &val, 2);
> stw_p(buf, val);
> - } else {
> + break;
> + case 1:
> /* 8 bit read access */
> error |= io_mem_read(mr, addr1, &val, 1);
> stb_p(buf, val);
> + break;
> + default:
> + abort();
> }
> } else {
> /* RAM case */
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2013-07-14 6:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 1:01 [Qemu-devel] [PATCH 0/4] alpha-softmmu fixes Richard Henderson
2013-07-09 1:01 ` [Qemu-devel] [PATCH 1/4] hw/alpha: Don't use get_system_io Richard Henderson
2013-07-09 1:01 ` [Qemu-devel] [PATCH 2/4] hw/alpha: Don't machine check on missing pci i/o Richard Henderson
2013-07-09 1:01 ` [Qemu-devel] [PATCH 3/4] exec: Support 64-bit operations in address_space_rw Richard Henderson
2013-07-14 6:38 ` Paolo Bonzini [this message]
2013-07-09 1:01 ` [Qemu-devel] [PATCH 4/4] hw/alpha: Drop latch_tmp hack Richard Henderson
2013-07-09 17:43 ` [Qemu-devel] [PATCH 0/4] alpha-softmmu fixes Rob Landley
2013-07-10 13:49 ` Richard Henderson
2013-07-14 6:05 ` Rob Landley
2013-07-15 1:19 ` Richard Henderson
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=51E2476C.20207@redhat.com \
--to=pbonzini@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.