virtio.c (275048) | virtio.c (275647) |
---|---|
1/*- 2 * Copyright (c) 2014 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 19 unchanged lines hidden (view full) --- 28 * SUCH DAMAGE. 29 */ 30 31/* 32 * BERI virtio mmio backend common methods 33 */ 34 35#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2014 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7 * ("CTSRD"), as part of the DARPA CRASH research programme. 8 * --- 19 unchanged lines hidden (view full) --- 28 * SUCH DAMAGE. 29 */ 30 31/* 32 * BERI virtio mmio backend common methods 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/dev/beri/virtio/virtio.c 275048 2014-11-25 15:58:59Z br $"); | 36__FBSDID("$FreeBSD: head/sys/dev/beri/virtio/virtio.c 275647 2014-12-09 16:39:21Z br $"); |
37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bus.h> 41#include <sys/kernel.h> 42#include <sys/module.h> 43#include <sys/malloc.h> 44#include <sys/rman.h> --- 8 unchanged lines hidden (view full) --- 53#include <sys/endian.h> 54#include <sys/rwlock.h> 55 56#include <machine/bus.h> 57#include <machine/fdt.h> 58#include <machine/cpu.h> 59#include <machine/intr.h> 60 | 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bus.h> 41#include <sys/kernel.h> 42#include <sys/module.h> 43#include <sys/malloc.h> 44#include <sys/rman.h> --- 8 unchanged lines hidden (view full) --- 53#include <sys/endian.h> 54#include <sys/rwlock.h> 55 56#include <machine/bus.h> 57#include <machine/fdt.h> 58#include <machine/cpu.h> 59#include <machine/intr.h> 60 |
61#include <dev/fdt/fdt_common.h> 62#include <dev/ofw/openfirm.h> 63#include <dev/ofw/ofw_bus.h> 64#include <dev/ofw/ofw_bus_subr.h> 65 |
|
61#include <dev/beri/virtio/virtio.h> 62#include <dev/virtio/virtio.h> 63#include <dev/virtio/virtqueue.h> 64#include <dev/virtio/virtio_ring.h> | 66#include <dev/beri/virtio/virtio.h> 67#include <dev/virtio/virtio.h> 68#include <dev/virtio/virtqueue.h> 69#include <dev/virtio/virtio_ring.h> |
70#include <dev/altera/pio/pio.h> |
|
65 | 71 |
72#include "pio_if.h" 73 |
|
66int 67vq_ring_ready(struct vqueue_info *vq) 68{ 69 70 return (vq->vq_flags & VQ_ALLOC); 71} 72 73int --- 88 unchanged lines hidden (view full) --- 162vq_relchain(struct vqueue_info *vq, struct iovec *iov, int n, uint32_t iolen) 163{ 164 volatile struct vring_used_elem *vue; 165 volatile struct vring_used *vu; 166 uint16_t head, uidx, mask; 167 int i; 168 169 mask = vq->vq_qsize - 1; | 74int 75vq_ring_ready(struct vqueue_info *vq) 76{ 77 78 return (vq->vq_flags & VQ_ALLOC); 79} 80 81int --- 88 unchanged lines hidden (view full) --- 170vq_relchain(struct vqueue_info *vq, struct iovec *iov, int n, uint32_t iolen) 171{ 172 volatile struct vring_used_elem *vue; 173 volatile struct vring_used *vu; 174 uint16_t head, uidx, mask; 175 int i; 176 177 mask = vq->vq_qsize - 1; |
178 vu = vq->vq_used; |
|
170 head = be16toh(vq->vq_avail->ring[vq->vq_last_avail++ & mask]); 171 | 179 head = be16toh(vq->vq_avail->ring[vq->vq_last_avail++ & mask]); 180 |
172 vu = vq->vq_used; | |
173 uidx = be16toh(vu->idx); 174 vue = &vu->ring[uidx++ & mask]; | 181 uidx = be16toh(vu->idx); 182 vue = &vu->ring[uidx++ & mask]; |
175 vue->id = htobe16(head); | 183 vue->id = htobe32(head); 184 |
176 vue->len = htobe32(iolen); 177 vu->idx = htobe16(uidx); 178 179 /* Clean up */ 180 for (i = 1; i < (n-1); i++) { 181 paddr_unmap((void *)iov[i].iov_base, iov[i].iov_len); 182 } 183} | 185 vue->len = htobe32(iolen); 186 vu->idx = htobe16(uidx); 187 188 /* Clean up */ 189 for (i = 1; i < (n-1); i++) { 190 paddr_unmap((void *)iov[i].iov_base, iov[i].iov_len); 191 } 192} |
193 194int 195setup_pio(device_t dev, char *name, device_t *pio_dev) 196{ 197 phandle_t pio_node; 198 struct fdt_ic *ic; 199 phandle_t xref; 200 phandle_t node; 201 202 if ((node = ofw_bus_get_node(dev)) == -1) 203 return (ENXIO); 204 205 if (OF_searchencprop(node, name, &xref, 206 sizeof(xref)) == -1) { 207 return (ENXIO); 208 } 209 210 pio_node = OF_node_from_xref(xref); 211 SLIST_FOREACH(ic, &fdt_ic_list_head, fdt_ics) { 212 if (ic->iph == pio_node) { 213 *pio_dev = ic->dev; 214 PIO_CONFIGURE(*pio_dev, PIO_OUT_ALL, 215 PIO_UNMASK_ALL); 216 return (0); 217 } 218 } 219 220 return (ENXIO); 221} 222 223int 224setup_offset(device_t dev, uint32_t *offset) 225{ 226 pcell_t dts_value[2]; 227 phandle_t mem_node; 228 phandle_t xref; 229 phandle_t node; 230 int len; 231 232 if ((node = ofw_bus_get_node(dev)) == -1) 233 return (ENXIO); 234 235 if (OF_searchencprop(node, "beri-mem", &xref, 236 sizeof(xref)) == -1) { 237 return (ENXIO); 238 } 239 240 mem_node = OF_node_from_xref(xref); 241 if ((len = OF_getproplen(mem_node, "reg")) <= 0) 242 return (ENXIO); 243 OF_getencprop(mem_node, "reg", dts_value, len); 244 *offset = dts_value[0]; 245 246 return (0); 247} 248 |
|