qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/5] ide/atapi: Use table instead of switch for commands
Date: Thu, 21 Apr 2011 10:13:43 +0200	[thread overview]
Message-ID: <4DAFE737.8070601@redhat.com> (raw)
In-Reply-To: <BANLkTikwjzTJyLiwQ5ESdDb=bbpjHk9+Tw@mail.gmail.com>

Am 20.04.2011 20:13, schrieb Blue Swirl:
> On Wed, Apr 20, 2011 at 2:30 PM, Kevin Wolf <kwolf@redhat.com> wrote:
>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> ---
>>  hw/ide/atapi.c |  115 +++++++++++++++++++++++--------------------------------
>>  1 files changed, 48 insertions(+), 67 deletions(-)
>>
>> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
>> index d161bf7..d0bf7fd 100644
>> --- a/hw/ide/atapi.c
>> +++ b/hw/ide/atapi.c
>> @@ -533,10 +533,11 @@ static unsigned int event_status_media(IDEState *s,
>>     return 8; /* We wrote to 4 extra bytes from the header */
>>  }
>>
>> -static void handle_get_event_status_notification(IDEState *s,
>> -                                                 uint8_t *buf,
>> -                                                 const uint8_t *packet)
>> +static void cmd_get_event_status_notification(IDEState *s,
>> +                                              uint8_t *buf)
>>  {
>> +    const uint8_t *packet = buf;
>> +
>>     struct {
>>         uint8_t opcode;
>>         uint8_t polled;        /* lsb bit is polled; others are reserved */
>> @@ -1064,6 +1065,38 @@ static void cmd_set_speed(IDEState *s, uint8_t* buf)
>>     ide_atapi_cmd_ok(s);
>>  }
>>
>> +enum {
>> +    /*
>> +     * Only commands flagged as ALLOW_UA are allowed to run under a
>> +     * unit attention condition. (See MMC-5, section 4.1.6.1)
>> +     */
>> +    ALLOW_UA = 0x01,
>> +};
>> +
>> +struct {
>> +    void (*handler)(IDEState *s, uint8_t *buf);
>> +    int flags;
>> +} atapi_cmd_table[0x100] = {
>> +    [ 0x00 ] = { cmd_test_unit_ready,               0 },
> 
> How about using symbols here, like
>     [ GPCMD_TEST_UNIT_READY ] = { cmd_test_unit_ready, 0 },
> ?

I avoided symbols intentionally. In fact, I'm even considering to remove
the symbols from the header file because most of them are unused now
(and it should be easy enough to get rid of the rest of them so that the
only occurrence of the literal opcode is in the table).

The point here is that this table contains all the information about a
command in one place. If you used symbols, you would have the command
name twice, and the opcode would be missing. So not using symbolic
constants but rather literal opcodes improves readability in this case.

> The table can probably be static const.

Right, will fix.

Kevin

  reply	other threads:[~2011-04-21  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20 11:30 [Qemu-devel] [PATCH v2 0/5] atapi: Some code restructuring Kevin Wolf
2011-04-20 11:30 ` [Qemu-devel] [PATCH v2 1/5] ide: Split atapi.c out Kevin Wolf
2011-04-25 10:09   ` Amit Shah
2011-04-20 11:30 ` [Qemu-devel] [PATCH v2 2/5] ide/atapi: Factor commands out Kevin Wolf
2011-04-20 11:30 ` [Qemu-devel] [PATCH v2 3/5] ide/atapi: Use table instead of switch for commands Kevin Wolf
2011-04-20 18:13   ` Blue Swirl
2011-04-21  8:13     ` Kevin Wolf [this message]
2011-04-25 10:14   ` Amit Shah
2011-04-20 11:30 ` [Qemu-devel] [PATCH v2 4/5] ide/atapi: Replace bdrv_get_geometry calls by s->nb_sectors Kevin Wolf
2011-04-20 11:30 ` [Qemu-devel] [PATCH v2 5/5] ide/atapi: Introduce CHECK_READY flag for commands Kevin Wolf
2011-04-25 10:19   ` Amit Shah

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=4DAFE737.8070601@redhat.com \
    --to=kwolf@redhat.com \
    --cc=blauwirbel@gmail.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).