[SLOF] [PATCH v1 17/27] virtio: make virtio_{get, read}_config 1.0 aware

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Thu Jan 14 22:10:53 AEDT 2016


Alexey Kardashevskiy <aik at ozlabs.ru> writes:

> On 01/13/2016 10:17 PM, Nikunj A Dadhania wrote:
>> Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
>> ---
>>   lib/libvirtio/virtio.c | 49 +++++++++++++++++++++++++++++--------------------
>>   1 file changed, 29 insertions(+), 20 deletions(-)
>>
>> diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
>> index 866ffb8..3bd8c67 100644
>> --- a/lib/libvirtio/virtio.c
>> +++ b/lib/libvirtio/virtio.c
>> @@ -480,35 +480,43 @@ void virtio_get_host_features_long(struct virtio_device *dev, uint64_t *features
>>   uint64_t virtio_get_config(struct virtio_device *dev, int offset, int size)
>>   {
>>   	uint64_t val = ~0ULL;
>> +	uint32_t hi, lo;
>>   	void *confbase;
>>
>> -	switch (dev->type) {
>> -	 case VIRTIO_TYPE_PCI:
>> +	if (dev->type != VIRTIO_TYPE_PCI)
>> +		return val;
>> +
>> +	if (dev->is_modern)
>> +		confbase = dev->device.addr;
>> +	else
>>   		confbase = dev->base+VIRTIOHDR_DEVICE_CONFIG;
>> -		break;
>> -	 default:
>> -		return ~0ULL;
>> -	}
>> +
>>   	switch (size) {
>> -	 case 1:
>> +	case 1:
>
> Too many unrelated changes :-/
>
>
>>   		val = ci_read_8(confbase+offset);
>>   		break;
>> -	 case 2:
>> +	case 2:
>>   		val = ci_read_16(confbase+offset);
>> +		if (dev->is_modern)
>> +			val = le16_to_cpu(val);
>>   		break;
>> -	 case 4:
>> +	case 4:
>>   		val = ci_read_32(confbase+offset);
>> +		if (dev->is_modern)
>> +			val = le32_to_cpu(val);
>>   		break;
>> -	 case 8:
>> +	case 8:
>>   		/* We don't support 8 bytes PIO accesses
>>   		 * in qemu and this is all PIO
>>   		 */
>> -		val = ci_read_32(confbase+offset);
>> -		val <<= 32;
>> -		val |= ci_read_32(confbase+offset+4);
>> +		lo = ci_read_32(confbase+offset);
>> +		hi = ci_read_32(confbase+offset+4);
>
>
> Does it have to be 2 separate 32bit reads or ci_read_64 can be used?

For reference virtio 1.0 Spec

4.1.3 PCI Device Layout

Fields of different sizes are present in the device configuration regions. All 64-bit, 32-bit and 16-bit fields
are little-endian. 64-bit fields are to be treated as two 32-bit fields, with low 32 bit part followed by the high
32 bit part.

Regards
Nikunj



More information about the SLOF mailing list