[SLOF] [PATCH v2 14/19] virtio: 1.0 features set/get register accessor

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Thu Jan 21 19:04:56 AEDT 2016


Thomas Huth <thuth at redhat.com> writes:

>>  
>> +/**
>> + * Set guest feature bits - virtio 1.0 interface
>> + */
>> +void virtio_set_guest_features_long(struct virtio_device *dev, uint64_t features)
>> +{
>> +	if (dev->type == VIRTIO_TYPE_PCI && dev->is_modern) {
>> +		uint32_t f1 = (features >> 32) & 0xFFFFFFFF;
>> +		uint32_t f0 = features & 0xFFFFFFFF;
>> +		void *addr = dev->common.addr;
>> +
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, drv_features_sel),
>> +			    bswap_32(1));
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, drv_features),
>> +			    bswap_32(f1));
>> +
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, drv_features_sel),
>> +			    bswap_32(0));
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, drv_features),
>> +			    bswap_32(f0));
>> +	}
>> +}
>> +
>> +/**
>> + * Get host feature bits - virtio 1.0 interface
>> + */
>> +void virtio_get_host_features_long(struct virtio_device *dev, uint64_t *features)
>> +{
>> +	if (dev->type == VIRTIO_TYPE_PCI && dev->is_modern && features) {
>> +		uint32_t f0 = 0, f1 = 0;
>> +		void *addr = dev->common.addr;
>> +
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, dev_features_sel),
>> +			    bswap_32(1));
>> +		f1 = ci_read_32(addr +
>> +				offset_of(struct virtio_dev_common, dev_features));
>> +		ci_write_32(addr + offset_of(struct virtio_dev_common, dev_features_sel),
>> +			    bswap_32(0));
>> +		f0 = ci_read_32(addr +
>> +				offset_of(struct virtio_dev_common, dev_features));
>> +
>> +		*features = ((uint64_t)le32_to_cpu(f1) << 32) | le32_to_cpu(f0);
>> +	}
>> +}
>
> Could you please use cpu_to_le32() instead of bswap_32() in the above
> two function? In the (unlikely) case that this code ever runs on a
> little endian CPU, it would be better to use cpu_to_le32() right from
> the start, I think...

Done.



More information about the SLOF mailing list