Lines Matching defs:sc
76 static void vtmmio_set_virtqueue(struct vtmmio_softc *sc,
106 #define vtmmio_write_config_1(sc, o, v) \
108 if (sc->platform != NULL) \
109 VIRTIO_MMIO_PREWRITE(sc->platform, (o), (v)); \
110 bus_write_1((sc)->res[0], (o), (v)); \
111 if (sc->platform != NULL) \
112 VIRTIO_MMIO_NOTE(sc->platform, (o), (v)); \
114 #define vtmmio_write_config_2(sc, o, v) \
116 if (sc->platform != NULL) \
117 VIRTIO_MMIO_PREWRITE(sc->platform, (o), (v)); \
118 bus_write_2((sc)->res[0], (o), (v)); \
119 if (sc->platform != NULL) \
120 VIRTIO_MMIO_NOTE(sc->platform, (o), (v)); \
122 #define vtmmio_write_config_4(sc, o, v) \
124 if (sc->platform != NULL) \
125 VIRTIO_MMIO_PREWRITE(sc->platform, (o), (v)); \
126 bus_write_4((sc)->res[0], (o), (v)); \
127 if (sc->platform != NULL) \
128 VIRTIO_MMIO_NOTE(sc->platform, (o), (v)); \
131 #define vtmmio_read_config_1(sc, o) \
132 bus_read_1((sc)->res[0], (o))
133 #define vtmmio_read_config_2(sc, o) \
134 bus_read_2((sc)->res[0], (o))
135 #define vtmmio_read_config_4(sc, o) \
136 bus_read_4((sc)->res[0], (o))
179 struct vtmmio_softc *sc;
183 sc = device_get_softc(dev);
186 sc->res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
188 if (sc->res[0] == NULL) {
193 magic = vtmmio_read_config_4(sc, VIRTIO_MMIO_MAGIC_VALUE);
196 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]);
200 version = vtmmio_read_config_4(sc, VIRTIO_MMIO_VERSION);
203 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]);
207 if (vtmmio_read_config_4(sc, VIRTIO_MMIO_DEVICE_ID) == 0) {
208 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]);
212 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]);
221 struct vtmmio_softc *sc;
225 sc = device_get_softc(dev);
227 if (sc->platform != NULL) {
228 err = VIRTIO_MMIO_SETUP_INTR(sc->platform, sc->dev,
229 vtmmio_vq_intr, sc);
237 sc->res[1] = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
239 if (!sc->res[1]) {
244 if (bus_setup_intr(dev, sc->res[1], type | INTR_MPSAFE,
245 NULL, vtmmio_vq_intr, sc, &sc->ih)) {
256 struct vtmmio_softc *sc;
260 sc = device_get_softc(dev);
261 sc->dev = dev;
264 sc->res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
266 if (sc->res[0] == NULL) {
271 sc->vtmmio_version = vtmmio_read_config_4(sc, VIRTIO_MMIO_VERSION);
273 vtmmio_reset(sc);
285 sc->vtmmio_child_dev = child;
286 vtmmio_probe_and_attach_child(sc);
294 struct vtmmio_softc *sc;
297 sc = device_get_softc(dev);
303 vtmmio_reset(sc);
305 if (sc->res[0] != NULL) {
307 sc->res[0]);
308 sc->res[0] = NULL;
343 struct vtmmio_softc *sc;
345 sc = device_get_softc(dev);
347 vtmmio_probe_and_attach_child(sc);
353 struct vtmmio_softc *sc;
355 sc = device_get_softc(dev);
357 vtmmio_reset(sc);
358 vtmmio_release_child_resources(sc);
364 struct vtmmio_softc *sc;
366 sc = device_get_softc(dev);
368 if (sc->vtmmio_child_dev != child)
374 *result = vtmmio_read_config_4(sc, VIRTIO_MMIO_DEVICE_ID);
377 *result = vtmmio_read_config_4(sc, VIRTIO_MMIO_VENDOR_ID);
392 *result = sc->vtmmio_version > 1;
404 struct vtmmio_softc *sc;
406 sc = device_get_softc(dev);
408 if (sc->vtmmio_child_dev != child)
413 sc->vtmmio_child_feat_desc = (void *) value;
425 struct vtmmio_softc *sc;
428 sc = device_get_softc(dev);
430 if (sc->vtmmio_version > 1) {
434 vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 1);
435 host_features = vtmmio_read_config_4(sc, VIRTIO_MMIO_HOST_FEATURES);
438 vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 0);
439 host_features |= vtmmio_read_config_4(sc, VIRTIO_MMIO_HOST_FEATURES);
441 vtmmio_describe_features(sc, "host", host_features);
449 sc->vtmmio_features = features;
451 vtmmio_describe_features(sc, "negotiated", features);
453 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES_SEL, 1);
454 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES, features >> 32);
456 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES_SEL, 0);
457 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES, features);
465 struct vtmmio_softc *sc;
468 sc = device_get_softc(dev);
470 if (sc->vtmmio_version > 1) {
490 struct vtmmio_softc *sc;
492 sc = device_get_softc(dev);
494 return ((sc->vtmmio_features & feature) != 0);
498 vtmmio_set_virtqueue(struct vtmmio_softc *sc, struct virtqueue *vq,
503 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_NUM, size);
505 if (sc->vtmmio_version == 1) {
506 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_ALIGN,
509 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_PFN,
513 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_DESC_LOW,
515 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_DESC_HIGH,
519 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_AVAIL_LOW,
521 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_AVAIL_HIGH,
525 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_USED_LOW,
527 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_USED_HIGH,
530 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_READY, 1);
540 struct vtmmio_softc *sc;
545 sc = device_get_softc(dev);
547 if (sc->vtmmio_nvqs != 0)
552 sc->vtmmio_vqs = malloc(nvqs * sizeof(struct vtmmio_virtqueue),
554 if (sc->vtmmio_vqs == NULL)
557 if (sc->vtmmio_version == 1) {
558 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_PAGE_SIZE,
563 vqx = &sc->vtmmio_vqs[idx];
566 vtmmio_select_virtqueue(sc, idx);
567 size = vtmmio_read_config_4(sc, VIRTIO_MMIO_QUEUE_NUM_MAX);
579 vtmmio_set_virtqueue(sc, vq, size);
584 sc->vtmmio_nvqs++;
588 vtmmio_free_virtqueues(sc);
603 struct vtmmio_softc *sc;
605 sc = device_get_softc(dev);
607 if (sc->platform != NULL)
608 VIRTIO_MMIO_POLL(sc->platform);
614 struct vtmmio_softc *sc;
617 sc = device_get_softc(dev);
640 if (sc->vtmmio_version == 1) {
641 vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_PAGE_SIZE,
645 for (idx = 0; idx < sc->vtmmio_nvqs; idx++) {
646 error = vtmmio_reinit_virtqueue(sc, idx);
664 struct vtmmio_softc *sc;
666 sc = device_get_softc(dev);
669 vtmmio_write_config_4(sc, offset, queue);
675 struct vtmmio_softc *sc;
678 sc = device_get_softc(dev);
680 if (sc->vtmmio_version > 1)
681 gen = vtmmio_read_config_4(sc, VIRTIO_MMIO_CONFIG_GENERATION);
691 struct vtmmio_softc *sc;
693 sc = device_get_softc(dev);
695 return (vtmmio_read_config_4(sc, VIRTIO_MMIO_STATUS));
701 struct vtmmio_softc *sc;
703 sc = device_get_softc(dev);
708 vtmmio_write_config_4(sc, VIRTIO_MMIO_STATUS, status);
715 struct vtmmio_softc *sc;
720 sc = device_get_softc(dev);
741 if (sc->vtmmio_version > 1) {
744 *(uint8_t *)dst = vtmmio_read_config_1(sc, off);
748 le16toh(vtmmio_read_config_2(sc, off));
752 le32toh(vtmmio_read_config_4(sc, off));
755 *(uint64_t *)dst = vtmmio_read_dev_config_8(sc, off);
768 *(uint32_t *)d = vtmmio_read_config_4(sc, off);
771 *(uint16_t *)d = vtmmio_read_config_2(sc, off);
776 *d = vtmmio_read_config_1(sc, off);
782 vtmmio_read_dev_config_8(struct vtmmio_softc *sc, bus_size_t off)
788 dev = sc->dev;
792 val0 = le32toh(vtmmio_read_config_4(sc, off));
793 val1 = le32toh(vtmmio_read_config_4(sc, off + 4));
803 struct vtmmio_softc *sc;
808 sc = device_get_softc(dev);
816 if (sc->vtmmio_version > 1) {
819 vtmmio_write_config_1(sc, off, *(const uint8_t *)src);
822 vtmmio_write_config_2(sc, off,
826 vtmmio_write_config_4(sc, off,
830 vtmmio_write_config_4(sc, off,
832 vtmmio_write_config_4(sc, off + 4,
846 vtmmio_write_config_4(sc, off, *(uint32_t *)s);
849 vtmmio_write_config_2(sc, off, *(uint16_t *)s);
854 vtmmio_write_config_1(sc, off, *s);
860 vtmmio_describe_features(struct vtmmio_softc *sc, const char *msg,
865 dev = sc->dev;
866 child = sc->vtmmio_child_dev;
871 virtio_describe(dev, msg, features, sc->vtmmio_child_feat_desc);
875 vtmmio_probe_and_attach_child(struct vtmmio_softc *sc)
879 dev = sc->dev;
880 child = sc->vtmmio_child_dev;
896 vtmmio_reset(sc);
897 vtmmio_release_child_resources(sc);
907 vtmmio_reinit_virtqueue(struct vtmmio_softc *sc, int idx)
914 vqx = &sc->vtmmio_vqs[idx];
919 vtmmio_select_virtqueue(sc, idx);
920 size = vtmmio_read_config_4(sc, VIRTIO_MMIO_QUEUE_NUM_MAX);
926 vtmmio_set_virtqueue(sc, vq, size);
932 vtmmio_free_interrupts(struct vtmmio_softc *sc)
935 if (sc->ih != NULL)
936 bus_teardown_intr(sc->dev, sc->res[1], sc->ih);
938 if (sc->res[1] != NULL)
939 bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->res[1]);
943 vtmmio_free_virtqueues(struct vtmmio_softc *sc)
948 for (idx = 0; idx < sc->vtmmio_nvqs; idx++) {
949 vqx = &sc->vtmmio_vqs[idx];
951 vtmmio_select_virtqueue(sc, idx);
952 if (sc->vtmmio_version > 1) {
953 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_READY, 0);
954 vtmmio_read_config_4(sc, VIRTIO_MMIO_QUEUE_READY);
956 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_PFN, 0);
962 free(sc->vtmmio_vqs, M_DEVBUF);
963 sc->vtmmio_vqs = NULL;
964 sc->vtmmio_nvqs = 0;
968 vtmmio_release_child_resources(struct vtmmio_softc *sc)
971 vtmmio_free_interrupts(sc);
972 vtmmio_free_virtqueues(sc);
976 vtmmio_reset(struct vtmmio_softc *sc)
983 vtmmio_set_status(sc->dev, VIRTIO_CONFIG_STATUS_RESET);
987 vtmmio_select_virtqueue(struct vtmmio_softc *sc, int idx)
990 vtmmio_write_config_4(sc, VIRTIO_MMIO_QUEUE_SEL, idx);
997 struct vtmmio_softc *sc;
1002 sc = arg;
1004 status = vtmmio_read_config_4(sc, VIRTIO_MMIO_INTERRUPT_STATUS);
1005 vtmmio_write_config_4(sc, VIRTIO_MMIO_INTERRUPT_ACK, status);
1009 if (sc->vtmmio_child_dev != NULL)
1010 VIRTIO_CONFIG_CHANGE(sc->vtmmio_child_dev);
1014 for (idx = 0; idx < sc->vtmmio_nvqs; idx++) {
1015 vqx = &sc->vtmmio_vqs[idx];