Lines Matching refs:dev
113 struct device *dev; member
151 struct device *dev; member
236 static u8 *get_feature_bits(struct device *dev) in get_feature_bits() argument
238 return (u8 *)(dev->desc + 1) in get_feature_bits()
239 + dev->num_vq * sizeof(struct lguest_vqconfig); in get_feature_bits()
800 struct console_abort *abort = vq->dev->priv; in console_input()
890 struct net_info *net_info = vq->dev->priv; in net_output()
937 struct net_info *net_info = vq->dev->priv; in net_input()
989 static void reset_device(struct device *dev) in reset_device() argument
993 verbose("Resetting device %s\n", dev->name); in reset_device()
996 memset(get_feature_bits(dev) + dev->feature_len, 0, dev->feature_len); in reset_device()
1002 for (vq = dev->vq; vq; vq = vq->next) { in reset_device()
1012 dev->running = false; in reset_device()
1056 static void start_device(struct device *dev) in start_device() argument
1061 verbose("Device %s OK: offered", dev->name); in start_device()
1062 for (i = 0; i < dev->feature_len; i++) in start_device()
1063 verbose(" %02x", get_feature_bits(dev)[i]); in start_device()
1065 for (i = 0; i < dev->feature_len; i++) in start_device()
1066 verbose(" %02x", get_feature_bits(dev) in start_device()
1067 [dev->feature_len+i]); in start_device()
1069 for (vq = dev->vq; vq; vq = vq->next) { in start_device()
1073 dev->running = true; in start_device()
1078 struct device *dev; in cleanup_devices() local
1080 for (dev = devices.dev; dev; dev = dev->next) in cleanup_devices()
1081 reset_device(dev); in cleanup_devices()
1089 static void update_device_status(struct device *dev) in update_device_status() argument
1092 if (dev->desc->status == 0) in update_device_status()
1093 reset_device(dev); in update_device_status()
1094 else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) { in update_device_status()
1095 warnx("Device %s configuration FAILED", dev->name); in update_device_status()
1096 if (dev->running) in update_device_status()
1097 reset_device(dev); in update_device_status()
1099 if (dev->running) in update_device_status()
1100 err(1, "Device %s features finalized twice", dev->name); in update_device_status()
1101 start_device(dev); in update_device_status()
1114 for (i = devices.dev; i; i = i->next) { in handle_output()
1160 static u8 *device_config(const struct device *dev) in device_config() argument
1162 return (void *)(dev->desc + 1) in device_config()
1163 + dev->num_vq * sizeof(struct lguest_vqconfig) in device_config()
1164 + dev->feature_len * 2; in device_config()
1196 static void add_virtqueue(struct device *dev, unsigned int num_descs, in add_virtqueue() argument
1211 vq->dev = dev; in add_virtqueue()
1234 assert(dev->desc->config_len == 0 && dev->desc->feature_len == 0); in add_virtqueue()
1235 memcpy(device_config(dev), &vq->config, sizeof(vq->config)); in add_virtqueue()
1236 dev->num_vq++; in add_virtqueue()
1237 dev->desc->num_vq++; in add_virtqueue()
1245 for (i = &dev->vq; *i; i = &(*i)->next); in add_virtqueue()
1253 static void add_feature(struct device *dev, unsigned bit) in add_feature() argument
1255 u8 *features = get_feature_bits(dev); in add_feature()
1258 if (dev->desc->feature_len <= bit / CHAR_BIT) { in add_feature()
1259 assert(dev->desc->config_len == 0); in add_feature()
1260 dev->feature_len = dev->desc->feature_len = (bit/CHAR_BIT) + 1; in add_feature()
1271 static void set_config(struct device *dev, unsigned len, const void *conf) in set_config() argument
1274 if (device_config(dev) + len > devices.descpage + getpagesize()) in set_config()
1278 memcpy(device_config(dev), conf, len); in set_config()
1279 dev->desc->config_len = len; in set_config()
1282 assert(dev->desc->config_len == len); in set_config()
1294 struct device *dev = malloc(sizeof(*dev)); in new_device() local
1297 dev->desc = new_dev_desc(type); in new_device()
1298 dev->name = name; in new_device()
1299 dev->vq = NULL; in new_device()
1300 dev->feature_len = 0; in new_device()
1301 dev->num_vq = 0; in new_device()
1302 dev->running = false; in new_device()
1303 dev->next = NULL; in new_device()
1312 devices.lastdev->next = dev; in new_device()
1314 devices.dev = dev; in new_device()
1315 devices.lastdev = dev; in new_device()
1317 return dev; in new_device()
1326 struct device *dev; in setup_console() local
1339 dev = new_device("console", VIRTIO_ID_CONSOLE); in setup_console()
1342 dev->priv = malloc(sizeof(struct console_abort)); in setup_console()
1343 ((struct console_abort *)dev->priv)->count = 0; in setup_console()
1351 add_virtqueue(dev, VIRTQUEUE_NUM, console_input); in setup_console()
1352 add_virtqueue(dev, VIRTQUEUE_NUM, console_output); in setup_console()
1491 struct device *dev; in setup_tun_net() local
1502 dev = new_device("net", VIRTIO_ID_NET); in setup_tun_net()
1503 dev->priv = net_info; in setup_tun_net()
1506 add_virtqueue(dev, VIRTQUEUE_NUM, net_input); in setup_tun_net()
1507 add_virtqueue(dev, VIRTQUEUE_NUM, net_output); in setup_tun_net()
1527 add_feature(dev, VIRTIO_NET_F_MAC); in setup_tun_net()
1541 add_feature(dev, VIRTIO_NET_F_CSUM); in setup_tun_net()
1542 add_feature(dev, VIRTIO_NET_F_GUEST_CSUM); in setup_tun_net()
1543 add_feature(dev, VIRTIO_NET_F_GUEST_TSO4); in setup_tun_net()
1544 add_feature(dev, VIRTIO_NET_F_GUEST_TSO6); in setup_tun_net()
1545 add_feature(dev, VIRTIO_NET_F_GUEST_ECN); in setup_tun_net()
1546 add_feature(dev, VIRTIO_NET_F_HOST_TSO4); in setup_tun_net()
1547 add_feature(dev, VIRTIO_NET_F_HOST_TSO6); in setup_tun_net()
1548 add_feature(dev, VIRTIO_NET_F_HOST_ECN); in setup_tun_net()
1550 add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC); in setup_tun_net()
1552 add_feature(dev, VIRTIO_F_ANY_LAYOUT); in setup_tun_net()
1553 set_config(dev, sizeof(conf), &conf); in setup_tun_net()
1595 struct vblk_info *vblk = vq->dev->priv; in blk_request()
1698 struct device *dev; in setup_block_file() local
1703 dev = new_device("block", VIRTIO_ID_BLOCK); in setup_block_file()
1706 add_virtqueue(dev, VIRTQUEUE_NUM, blk_request); in setup_block_file()
1709 vblk = dev->priv = malloc(sizeof(*vblk)); in setup_block_file()
1716 add_feature(dev, VIRTIO_BLK_F_FLUSH); in setup_block_file()
1725 add_feature(dev, VIRTIO_BLK_F_SEG_MAX); in setup_block_file()
1729 set_config(dev, offsetof(struct virtio_blk_config, geometry), &conf); in setup_block_file()
1751 struct rng_info *rng_info = vq->dev->priv; in rng_input()
1780 struct device *dev; in setup_rng() local
1787 dev = new_device("rng", VIRTIO_ID_RNG); in setup_rng()
1788 dev->priv = rng_info; in setup_rng()
1791 add_virtqueue(dev, VIRTQUEUE_NUM, rng_input); in setup_rng()