Changeset 341df5f in mainline for uspace/lib/virtio/virtio-pci.c


Ignore:
Timestamp:
2018-05-22T19:06:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2d4faf7
Parents:
cbcb34c
git-author:
Jakub Jermar <jakub@…> (2018-05-05 20:07:00)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:50)
Message:

Factor our generic virtio device initialization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/virtio/virtio-pci.c

    rcbcb34c r341df5f  
    272272}
    273273
     274/**
     275 * Perform device initialization as described in section 3.1.1 of the
     276 * specification, steps 1 - 6.
     277 */
     278errno_t virtio_device_setup_start(virtio_dev_t *vdev, uint32_t features)
     279{
     280        virtio_pci_common_cfg_t *cfg = vdev->common_cfg;
     281
     282        /* 1. Reset the device */
     283        uint8_t status = VIRTIO_DEV_STATUS_RESET;
     284        pio_write_8(&cfg->device_status, status);
     285
     286        /* 2. Acknowledge we found the device */
     287        status |= VIRTIO_DEV_STATUS_ACKNOWLEDGE;
     288        pio_write_8(&cfg->device_status, status);
     289
     290        /* 3. We know how to drive the device */
     291        status |= VIRTIO_DEV_STATUS_DRIVER;
     292        pio_write_8(&cfg->device_status, status);
     293
     294        /* 4. Read the offered feature flags */
     295        pio_write_32(&cfg->device_feature_select, VIRTIO_FEATURES_0_31);
     296        uint32_t device_features = pio_read_32(&cfg->device_feature);
     297
     298        ddf_msg(LVL_NOTE, "offered features %x", device_features);
     299        features &= device_features;
     300
     301        if (!features)
     302                return ENOTSUP;
     303
     304        /* 4. Write the accepted feature flags */
     305        pio_write_32(&cfg->driver_feature_select, VIRTIO_FEATURES_0_31);
     306        pio_write_32(&cfg->driver_feature, features);
     307
     308        ddf_msg(LVL_NOTE, "accepted features %x", features);
     309
     310        /* 5. Set FEATURES_OK */
     311        status |= VIRTIO_DEV_STATUS_FEATURES_OK;
     312        pio_write_8(&cfg->device_status, status);
     313
     314        /* 6. Test if the device supports our feature subset */
     315        status = pio_read_8(&cfg->device_status);
     316        if (!(status & VIRTIO_DEV_STATUS_FEATURES_OK))
     317                return ENOTSUP;
     318
     319        return EOK;
     320}
     321
     322/**
     323 * Perform device initialization as described in section 3.1.1 of the
     324 * specification, step 8 (go live).
     325 */
     326void virtio_device_setup_finalize(virtio_dev_t *vdev)
     327{
     328        virtio_pci_common_cfg_t *cfg = vdev->common_cfg;
     329
     330        /* 8. Go live */
     331        uint8_t status = pio_read_8(&cfg->device_status);
     332        pio_write_8(&cfg->device_status, status | VIRTIO_DEV_STATUS_DRIVER_OK);
     333}
     334
     335void virtio_device_setup_fail(virtio_dev_t *vdev)
     336{
     337        virtio_pci_common_cfg_t *cfg = vdev->common_cfg;
     338
     339        uint8_t status = pio_read_8(&cfg->device_status);
     340        pio_write_8(&cfg->device_status, status | VIRTIO_DEV_STATUS_FAILED);
     341}
     342
    274343errno_t virtio_pci_dev_initialize(ddf_dev_t *dev, virtio_dev_t *vdev)
    275344{
Note: See TracChangeset for help on using the changeset viewer.