mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36:28 +08:00
virtio-pci-modern: replace pci_read/write_mmio_xxx with pci_read/write_io_xxx
Use IO api to access the io region Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
This commit is contained in:
+35
-35
@@ -358,8 +358,8 @@ virtio_pci_get_queue_len(FAR struct virtio_pci_device_s *vpdev, int idx)
|
|||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_select, idx);
|
pci_write_io_word(vpdev->dev, &cfg->queue_select, idx);
|
||||||
pci_read_mmio_word(vpdev->dev, &cfg->queue_size, &size);
|
pci_read_io_word(vpdev->dev, &cfg->queue_size, &size);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,19 +375,19 @@ static int virtio_pci_config_virtqueue(FAR struct virtio_pci_device_s *vpdev,
|
|||||||
|
|
||||||
/* Activate the queue */
|
/* Activate the queue */
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_select, vq->vq_queue_index);
|
pci_write_io_word(vpdev->dev, &cfg->queue_select, vq->vq_queue_index);
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_size, vq->vq_ring.num);
|
pci_write_io_word(vpdev->dev, &cfg->queue_size, vq->vq_ring.num);
|
||||||
|
|
||||||
pci_write_mmio_qword(vpdev, &cfg->queue_desc,
|
pci_write_io_qword(vpdev->dev, &cfg->queue_desc,
|
||||||
up_addrenv_va_to_pa(vq->vq_ring.desc));
|
up_addrenv_va_to_pa(vq->vq_ring.desc));
|
||||||
pci_write_mmio_qword(vpdev, &cfg->queue_avail,
|
pci_write_io_qword(vpdev->dev, &cfg->queue_avail,
|
||||||
up_addrenv_va_to_pa(vq->vq_ring.avail));
|
up_addrenv_va_to_pa(vq->vq_ring.avail));
|
||||||
pci_write_mmio_qword(vpdev, &cfg->queue_used,
|
pci_write_io_qword(vpdev->dev, &cfg->queue_used,
|
||||||
up_addrenv_va_to_pa(vq->vq_ring.used));
|
up_addrenv_va_to_pa(vq->vq_ring.used));
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_msix_vector,
|
pci_write_io_word(vpdev->dev, &cfg->queue_msix_vector,
|
||||||
VIRTIO_PCI_INT_VQ);
|
VIRTIO_PCI_INT_VQ);
|
||||||
pci_read_mmio_word(vpdev->dev, &cfg->queue_msix_vector, &msix_vector);
|
pci_read_io_word(vpdev->dev, &cfg->queue_msix_vector, &msix_vector);
|
||||||
if (msix_vector == VIRTIO_PCI_MSI_NO_VECTOR)
|
if (msix_vector == VIRTIO_PCI_MSI_NO_VECTOR)
|
||||||
{
|
{
|
||||||
vrterr("Msix_vector is no vector\n");
|
vrterr("Msix_vector is no vector\n");
|
||||||
@@ -396,7 +396,7 @@ static int virtio_pci_config_virtqueue(FAR struct virtio_pci_device_s *vpdev,
|
|||||||
|
|
||||||
/* Enable vq */
|
/* Enable vq */
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_enable, 1);
|
pci_write_io_word(vpdev->dev, &cfg->queue_enable, 1);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,8 +411,8 @@ static int virtio_pci_get_notify_offset(FAR struct virtqueue *vq)
|
|||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
uint16_t off;
|
uint16_t off;
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_select, vq->vq_queue_index);
|
pci_write_io_word(vpdev->dev, &cfg->queue_select, vq->vq_queue_index);
|
||||||
pci_read_mmio_word(vpdev->dev, &cfg->queue_notify_off, &off);
|
pci_read_io_word(vpdev->dev, &cfg->queue_notify_off, &off);
|
||||||
|
|
||||||
if (off * vpdev->notify_off_multiplier + 2 > vpdev->notify_len)
|
if (off * vpdev->notify_off_multiplier + 2 > vpdev->notify_len)
|
||||||
{
|
{
|
||||||
@@ -432,9 +432,9 @@ virtio_pci_config_virtdevice(FAR struct virtio_pci_device_s *vpdev)
|
|||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
uint16_t rvector;
|
uint16_t rvector;
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->config_msix_vector,
|
pci_write_io_word(vpdev->dev, &cfg->config_msix_vector,
|
||||||
VIRTIO_PCI_INT_CFG);
|
VIRTIO_PCI_INT_CFG);
|
||||||
pci_read_mmio_word(vpdev->dev, &cfg->config_msix_vector, &rvector);
|
pci_read_io_word(vpdev->dev, &cfg->config_msix_vector, &rvector);
|
||||||
if (rvector == VIRTIO_PCI_MSI_NO_VECTOR)
|
if (rvector == VIRTIO_PCI_MSI_NO_VECTOR)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -596,9 +596,9 @@ static void virtio_pci_delete_virtqueues(FAR struct virtio_device *vdev)
|
|||||||
{
|
{
|
||||||
vrinfo = &vdev->vrings_info[i];
|
vrinfo = &vdev->vrings_info[i];
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_select,
|
pci_write_io_word(vpdev->dev, &cfg->queue_select,
|
||||||
vrinfo->vq->vq_queue_index);
|
vrinfo->vq->vq_queue_index);
|
||||||
pci_write_mmio_word(vpdev->dev, &cfg->queue_msix_vector,
|
pci_write_io_word(vpdev->dev, &cfg->queue_msix_vector,
|
||||||
VIRTIO_PCI_MSI_NO_VECTOR);
|
VIRTIO_PCI_MSI_NO_VECTOR);
|
||||||
|
|
||||||
/* Free the vring buffer and virtqueue */
|
/* Free the vring buffer and virtqueue */
|
||||||
@@ -629,7 +629,7 @@ static void virtio_pci_set_status(FAR struct virtio_device *vdev,
|
|||||||
(FAR struct virtio_pci_device_s *)vdev;
|
(FAR struct virtio_pci_device_s *)vdev;
|
||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
|
|
||||||
pci_write_mmio_byte(vpdev->dev, &cfg->device_status, status);
|
pci_write_io_byte(vpdev->dev, &cfg->device_status, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -643,7 +643,7 @@ static uint8_t virtio_pci_get_status(FAR struct virtio_device *vdev)
|
|||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
pci_read_mmio_byte(vpdev->dev, &cfg->device_status, &status);
|
pci_read_io_byte(vpdev->dev, &cfg->device_status, &status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,19 +671,19 @@ static void virtio_pci_write_config(FAR struct virtio_device *vdev,
|
|||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
memcpy(&u8data, src, sizeof(u8data));
|
memcpy(&u8data, src, sizeof(u8data));
|
||||||
pci_write_mmio_byte(vpdev->dev, vpdev->device + offset, u8data);
|
pci_write_io_byte(vpdev->dev, vpdev->device + offset, u8data);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
memcpy(&u16data, src, sizeof(u16data));
|
memcpy(&u16data, src, sizeof(u16data));
|
||||||
pci_write_mmio_word(vpdev->dev, vpdev->device + offset, u16data);
|
pci_write_io_word(vpdev->dev, vpdev->device + offset, u16data);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
memcpy(&u32data, src, sizeof(u32data));
|
memcpy(&u32data, src, sizeof(u32data));
|
||||||
pci_write_mmio_dword(vpdev->dev, vpdev->device + offset, u32data);
|
pci_write_io_dword(vpdev->dev, vpdev->device + offset, u32data);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
memcpy(&u64data, src, sizeof(u64data));
|
memcpy(&u64data, src, sizeof(u64data));
|
||||||
pci_write_mmio_dword(vpdev->dev, vpdev->device + offset, u64data);
|
pci_write_io_qword(vpdev->dev, vpdev->device + offset, u64data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@@ -691,7 +691,7 @@ static void virtio_pci_write_config(FAR struct virtio_device *vdev,
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
pci_write_mmio_byte(&vmdev->cfg_io, vpdev->device + offset + i,
|
pci_write_io_byte(vpdev->dev, vpdev->device + offset + i,
|
||||||
s[i]);
|
s[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -721,19 +721,19 @@ static void virtio_pci_read_config(FAR struct virtio_device *vdev,
|
|||||||
switch (length)
|
switch (length)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
pci_read_mmio_byte(vpdev->dev, vpdev->device + offset, &u8data);
|
pci_read_io_byte(vpdev->dev, vpdev->device + offset, &u8data);
|
||||||
memcpy(dst, &u8data, sizeof(u8data));
|
memcpy(dst, &u8data, sizeof(u8data));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
pci_read_mmio_word(vpdev->dev, vpdev->device + offset, &u16data);
|
pci_read_io_word(vpdev->dev, vpdev->device + offset, &u16data);
|
||||||
memcpy(dst, &u16data, sizeof(u16data));
|
memcpy(dst, &u16data, sizeof(u16data));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
pci_read_mmio_dword(vpdev->dev, vpdev->device + offset, &u32data);
|
pci_read_io_dword(vpdev->dev, vpdev->device + offset, &u32data);
|
||||||
memcpy(dst, &u32data, sizeof(u32data));
|
memcpy(dst, &u32data, sizeof(u32data));
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
pci_read_mmio_qword(vpdev->dev, vpdev->device + offset, &u64data);
|
pci_read_io_qword(vpdev->dev, vpdev->device + offset, &u64data);
|
||||||
memcpy(dst, &u64data, sizeof(u64data));
|
memcpy(dst, &u64data, sizeof(u64data));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -742,7 +742,7 @@ static void virtio_pci_read_config(FAR struct virtio_device *vdev,
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
pci_read_mmio_byte(&vmdev->cfg_io, vpdev->device + offset + i,
|
pci_read_io_byte(vpdev->dev, vpdev->device + offset + i,
|
||||||
&d[i]);
|
&d[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,8 +760,8 @@ static uint32_t virtio_pci_get_features(FAR struct virtio_device *vdev)
|
|||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
uint32_t feature;
|
uint32_t feature;
|
||||||
|
|
||||||
pci_write_mmio_dword(vpdev->dev, &cfg->device_feature_select, 0);
|
pci_write_io_dword(vpdev->dev, &cfg->device_feature_select, 0);
|
||||||
pci_read_mmio_dword(vpdev->dev, &cfg->device_feature, &feature);
|
pci_read_io_dword(vpdev->dev, &cfg->device_feature, &feature);
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,10 +776,10 @@ static void virtio_pci_set_features(FAR struct virtio_device *vdev,
|
|||||||
(FAR struct virtio_pci_device_s *)vdev;
|
(FAR struct virtio_pci_device_s *)vdev;
|
||||||
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
FAR struct virtio_pci_common_cfg_s *cfg = vpdev->common;
|
||||||
|
|
||||||
pci_write_mmio_dword(vpdev->dev, &cfg->driver_feature_select, 0);
|
pci_write_io_dword(vpdev->dev, &cfg->driver_feature_select, 0);
|
||||||
pci_write_mmio_dword(vpdev->dev, &cfg->driver_feature, features);
|
pci_write_io_dword(vpdev->dev, &cfg->driver_feature, features);
|
||||||
pci_write_mmio_dword(vpdev->dev, &cfg->driver_feature_select, 1);
|
pci_write_io_dword(vpdev->dev, &cfg->driver_feature_select, 1);
|
||||||
pci_write_mmio_dword(vpdev->dev, &cfg->driver_feature, 0);
|
pci_write_io_dword(vpdev->dev, &cfg->driver_feature, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -815,7 +815,7 @@ static void virtio_pci_notify(FAR struct virtqueue *vq)
|
|||||||
|
|
||||||
vrinfo = &vpdev->vdev.vrings_info[vq->vq_queue_index];
|
vrinfo = &vpdev->vdev.vrings_info[vq->vq_queue_index];
|
||||||
|
|
||||||
pci_write_mmio_word(vpdev->dev, vpdev->notify + vrinfo->notifyid,
|
pci_write_io_word(vpdev->dev, vpdev->notify + vrinfo->notifyid,
|
||||||
vq->vq_queue_index);
|
vq->vq_queue_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user