[PATCH qemu 20/38] aspeed/smc: handle dummy bytes when doing fast reads

Cédric Le Goater clg at kaod.org
Mon Nov 21 23:50:17 AEDT 2016


On 11/21/2016 08:25 AM, Joel Stanley wrote:
> On Sat, Nov 19, 2016 at 12:52 AM, Cédric Le Goater <clg at kaod.org> wrote:
>> diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
>> index 9596ea94a3bc..c0ae07ef8c96 100644
>> --- a/hw/ssi/aspeed_smc.c
>> +++ b/hw/ssi/aspeed_smc.c
> 
>> @@ -525,27 +534,49 @@ static void aspeed_smc_flash_setup_read(AspeedSMCFlash *fl, uint32_t addr)
>>      ssi_transfer(s->spi, (addr & 0xff));
>>  }
>>
>> +static int aspeed_smc_flash_dummies(const AspeedSMCFlash *fl)
>> +{
>> +    AspeedSMCState *s = fl->controller;
>> +    uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->id];
>> +
>> +    return ((((r_ctrl0 >> CTRL_DUMMY_HIGH_SHIFT) & 0x1) << 2) |
>> +            ((r_ctrl0 >> CTRL_DUMMY_LOW_SHIFT) & 0x3)) * 8;
> 
> This is crazy :)

Isn't that lovely :) 

Here's another nice one that we have merged already :

	https://github.com/openbmc/qemu/blob/master/include/hw/misc/aspeed_scu.h#L100

> It might be easier to read if we had a few local variables. Might not
> though, so it's up to you.

yeah. This is not a macro. I can add a dummy_low and a dummy_high to ease
reading.

>> +}
>> +
>> +static uint64_t aspeed_smc_flash_do_read(AspeedSMCFlash *fl, unsigned size)
>> +{
>> +    AspeedSMCState *s = fl->controller;
>> +    uint64_t ret = 0;
>> +    int i;
>> +
>> +    if (fl->cmd == SPI_OP_READ_FAST) {
>> +        for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
>> +            ssi_transfer(s->spi, 0x0);
> 
> Do you need to check the return value here as well, like you do below?

no we don't. the m25p80 model simulates dummy cycles with dummy writes, so
we can discard the return value which is a zero.

C. 

>> +        }
>> +    }
>> +    fl->cmd = 0;
>> +
>> +    for (i = 0; i < size; i++) {
>> +        ret |= ssi_transfer(s->spi, 0x0) << (8 * i);
>> +    }
>> +    return ret;
>> +}



More information about the openbmc mailing list