[dpdk-dev] [PATCH v4 7/8] virtio: add 1.0 support

Xie, Huawei huawei.xie at intel.com
Mon Jan 18 18:07:51 CET 2016


.On 1/15/2016 12:34 PM, Yuanhan Liu wrote:
> Modern (v1.0) virtio pci device defines several pci capabilities.
> Each cap has a configure structure corresponding to it, and the
> cap.bar and cap.offset fields tell us where to find it.
>
[snip]
> +
> +static inline void
> +io_write64_twopart(uint64_t val, uint32_t *lo, uint32_t *hi)
> +{
> +	io_write32((uint32_t)val, lo);
> +	io_write32(val >> 32,     hi);

Firstly your second iowrite32 doesn't do the conversion. The conversion
is duplicated.

> +}
> +
> +static void
> +modern_read_dev_config(struct virtio_hw *hw, uint64_t offset,

here and there, size_t is more accurate for offset as we get it from
offsetof.

> +		       void *dst, int length)
> +{
> +	int i;
> +	uint8_t *p;
> +	uint8_t old_gen, new_gen;
> +
> +	do {
> +		old_gen = io_read8(&hw->common_cfg->config_generation);
> +
> +		p = dst;
> +		for (i = 0;  i < length; i++)
> +			*p++ = io_read8((uint8_t *)hw->dev_cfg + offset + i);
> +
> +		new_gen = io_read8(&hw->common_cfg->config_generation);
> +	} while (old_gen != new_gen);
> +}
> +
> +static void
> +modern_write_dev_config(struct virtio_hw *hw, uint64_t offset,
> +			const void *src, int length)
> +{
> +	int i;
> +	const uint8_t *p = src;
> +
> +	for (i = 0;  i < length; i++)
> +		io_write8(*p++, (uint8_t *)hw->dev_cfg + offset + i);
> +}
> +
> +static uint64_t
> +modern_get_features(struct virtio_hw *hw)
> +{
> +	uint32_t features_lo, features_hi;
> +
> +	io_write32(0, &hw->common_cfg->device_feature_select);
> +	features_lo = io_read32(&hw->common_cfg->device_feature);
> +
> +	io_write32(1, &hw->common_cfg->device_feature_select);
> +	features_hi = io_read32(&hw->common_cfg->device_feature);
> +
> +	return ((uint64_t)(features_hi) << 32) | features_lo;
> +}
> +
> +static void
> +modern_set_features(struct virtio_hw *hw, uint64_t features)
> +{
> +	io_write32(0, &hw->common_cfg->guest_feature_select);
> +	io_write32(features & ((1ULL << 32) - 1),

again, duplicated conversion

> +		&hw->common_cfg->guest_feature);
> +
> +	io_write32(1, &hw->common_cfg->guest_feature_select);
[snip]


More information about the dev mailing list