From: Hans-Erik Floryd <hans-erik.floryd@rt-labs.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] PL181 write problem
Date: Thu, 29 Jan 2009 19:37:13 +0100 [thread overview]
Message-ID: <4981F759.2040803@rt-labs.com> (raw)
Hello,
The PL181 sdcard module (hw/pl181.c) doesn't seem to handle writes
correctly. Only every fourth byte gets written to the card. I've tracked
the problem down to the following loop in pl181_fifo_run():
limit = is_read ? PL181_FIFO_LEN : 0;
n = 0;
value = 0;
while (s->datacnt && s->fifo_len != limit) {
if (is_read) {
value |= (uint32_t)sd_read_data(s->card) << (n * 8);
n++;
if (n == 4) {
pl181_fifo_push(s, value);
value = 0;
n = 0;
}
} else {
if (n == 0) {
value = pl181_fifo_pop(s);
n = 4;
}
sd_write_data(s->card, value & 0xff);
value >>= 8;
n--;
}
s->datacnt--;
}
When writing, a 32-bit value is popped from the fifo, followed by a
write of 1 byte. If there was only one value in the fifo, fifo_len will
now be 0. This causes the loop to terminate and the remaining three
bytes will not be written.
The following patch fixes this by writing all four bytes before checking
fifo_len.
Let me know if there's anything else I need to do to get the patch accepted.
Thanks
Index: hw/pl181.c
===================================================================
--- hw/pl181.c (revision 5648)
+++ hw/pl181.c (working copy)
@@ -202,16 +202,20 @@
value = 0;
n = 0;
}
+ s->datacnt--;
} else {
if (n == 0) {
value = pl181_fifo_pop(s);
n = 4;
}
- sd_write_data(s->card, value & 0xff);
- value >>= 8;
- n--;
+ while (s->datacnt && n != 0)
+ {
+ sd_write_data(s->card, value & 0xff);
+ value >>= 8;
+ n--;
+ s->datacnt--;
+ }
}
- s->datacnt--;
}
if (n && is_read) {
pl181_fifo_push(s, value);
next reply other threads:[~2009-01-29 18:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-29 18:37 Hans-Erik Floryd [this message]
2009-01-30 14:40 ` [Qemu-devel] PL181 write problem Paul Brook
2009-02-02 15:36 ` Hans-Erik Floryd
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=4981F759.2040803@rt-labs.com \
--to=hans-erik.floryd@rt-labs.com \
--cc=qemu-devel@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).