Lines Matching +full:data +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/virtio-uml.h>
23 /* for MSI-X we have a 32-bit payload */
61 u8 data[8]; member
84 return -EINVAL; in um_pci_send_cmd()
86 switch (cmd->op) { in um_pci_send_cmd()
129 ret = virtqueue_add_sgs(dev->cmd_vq, sgs_list, in um_pci_send_cmd()
138 virtqueue_kick(dev->cmd_vq); in um_pci_send_cmd()
144 set_bit(UM_PCI_STAT_WAITING, &dev->status); in um_pci_send_cmd()
145 virtqueue_kick(dev->cmd_vq); in um_pci_send_cmd()
148 void *completed = virtqueue_get_buf(dev->cmd_vq, &len); in um_pci_send_cmd()
156 if (WARN_ONCE(virtqueue_is_broken(dev->cmd_vq) || in um_pci_send_cmd()
158 "um virt-pci delay: %d", delay_count)) { in um_pci_send_cmd()
159 ret = -EIO; in um_pci_send_cmd()
164 clear_bit(UM_PCI_STAT_WAITING, &dev->status); in um_pci_send_cmd()
172 int size) in um_pci_cfgspace_read() argument
175 struct um_pci_device *dev = reg->dev; in um_pci_cfgspace_read()
178 .size = size, in um_pci_cfgspace_read()
181 /* buf->data is maximum size - we may only use parts of it */ in um_pci_cfgspace_read()
183 u8 *data; in um_pci_cfgspace_read() local
190 data = buf->data; in um_pci_cfgspace_read()
192 memset(buf->data, 0xff, sizeof(buf->data)); in um_pci_cfgspace_read()
194 switch (size) { in um_pci_cfgspace_read()
203 WARN(1, "invalid config space read size %d\n", size); in um_pci_cfgspace_read()
207 if (um_pci_send_cmd(dev, &hdr, sizeof(hdr), NULL, 0, data, 8)) in um_pci_cfgspace_read()
210 switch (size) { in um_pci_cfgspace_read()
212 ret = data[0]; in um_pci_cfgspace_read()
215 ret = le16_to_cpup((void *)data); in um_pci_cfgspace_read()
218 ret = le32_to_cpup((void *)data); in um_pci_cfgspace_read()
222 ret = le64_to_cpup((void *)data); in um_pci_cfgspace_read()
234 static void um_pci_cfgspace_write(void *priv, unsigned int offset, int size, in um_pci_cfgspace_write() argument
238 struct um_pci_device *dev = reg->dev; in um_pci_cfgspace_write()
241 /* maximum size - we may only use parts of it */ in um_pci_cfgspace_write()
242 u8 data[8]; in um_pci_cfgspace_write() member
246 .size = size, in um_pci_cfgspace_write()
254 switch (size) { in um_pci_cfgspace_write()
256 msg.data[0] = (u8)val; in um_pci_cfgspace_write()
259 put_unaligned_le16(val, (void *)msg.data); in um_pci_cfgspace_write()
262 put_unaligned_le32(val, (void *)msg.data); in um_pci_cfgspace_write()
266 put_unaligned_le64(val, (void *)msg.data); in um_pci_cfgspace_write()
270 WARN(1, "invalid config space write size %d\n", size); in um_pci_cfgspace_write()
283 unsigned int offset, int size) in um_pci_bar_copy_from() argument
286 struct um_pci_device *dev = container_of(resptr - *resptr, in um_pci_bar_copy_from()
292 .size = size, in um_pci_bar_copy_from()
296 memset(buffer, 0xff, size); in um_pci_bar_copy_from()
298 um_pci_send_cmd(dev, &hdr, sizeof(hdr), NULL, 0, buffer, size); in um_pci_bar_copy_from()
302 int size) in um_pci_bar_read() argument
304 /* buf->data is maximum size - we may only use parts of it */ in um_pci_bar_read()
306 u8 *data; in um_pci_bar_read() local
310 data = buf->data; in um_pci_bar_read()
312 switch (size) { in um_pci_bar_read()
321 WARN(1, "invalid config space read size %d\n", size); in um_pci_bar_read()
325 um_pci_bar_copy_from(priv, data, offset, size); in um_pci_bar_read()
327 switch (size) { in um_pci_bar_read()
329 ret = data[0]; in um_pci_bar_read()
332 ret = le16_to_cpup((void *)data); in um_pci_bar_read()
335 ret = le32_to_cpup((void *)data); in um_pci_bar_read()
339 ret = le64_to_cpup((void *)data); in um_pci_bar_read()
352 const void *buffer, int size) in um_pci_bar_copy_to() argument
355 struct um_pci_device *dev = container_of(resptr - *resptr, in um_pci_bar_copy_to()
361 .size = size, in um_pci_bar_copy_to()
365 um_pci_send_cmd(dev, &hdr, sizeof(hdr), buffer, size, NULL, 0); in um_pci_bar_copy_to()
368 static void um_pci_bar_write(void *priv, unsigned int offset, int size, in um_pci_bar_write() argument
371 /* maximum size - we may only use parts of it */ in um_pci_bar_write()
372 u8 data[8]; in um_pci_bar_write() local
374 switch (size) { in um_pci_bar_write()
376 data[0] = (u8)val; in um_pci_bar_write()
379 put_unaligned_le16(val, (void *)data); in um_pci_bar_write()
382 put_unaligned_le32(val, (void *)data); in um_pci_bar_write()
386 put_unaligned_le64(val, (void *)data); in um_pci_bar_write()
390 WARN(1, "invalid config space write size %d\n", size); in um_pci_bar_write()
394 um_pci_bar_copy_to(priv, offset, data, size); in um_pci_bar_write()
397 static void um_pci_bar_set(void *priv, unsigned int offset, u8 value, int size) in um_pci_bar_set() argument
400 struct um_pci_device *dev = container_of(resptr - *resptr, in um_pci_bar_set()
405 u8 data; in um_pci_bar_set() member
410 .size = size, in um_pci_bar_set()
413 .data = value, in um_pci_bar_set()
431 unsigned int busn = bus->number; in um_pci_map_bus()
447 return (void __iomem *)((unsigned long)dev->iomem + where); in um_pci_map_bus()
459 pci_rescan_bus(bridge->bus); in um_pci_rescan()
477 struct virtio_device *vdev = vq->vdev; in um_pci_handle_irq_message()
478 struct um_pci_device *dev = vdev->priv; in um_pci_handle_irq_message()
482 switch (msg->op) { in um_pci_handle_irq_message()
484 generic_handle_irq(dev->irq); in um_pci_handle_irq_message()
488 if (msg->size == sizeof(u32)) in um_pci_handle_irq_message()
489 generic_handle_irq(le32_to_cpup((void *)msg->data)); in um_pci_handle_irq_message()
491 generic_handle_irq(le16_to_cpup((void *)msg->data)); in um_pci_handle_irq_message()
494 /* nothing to do - we already woke up due to the message */ in um_pci_handle_irq_message()
497 dev_err(&vdev->dev, "unexpected virt-pci message %d\n", msg->op); in um_pci_handle_irq_message()
504 struct virtio_device *vdev = vq->vdev; in um_pci_cmd_vq_cb()
505 struct um_pci_device *dev = vdev->priv; in um_pci_cmd_vq_cb()
509 if (test_bit(UM_PCI_STAT_WAITING, &dev->status)) in um_pci_cmd_vq_cb()
540 err = virtio_find_vqs(dev->vdev, 2, vqs, cbs, names, NULL); in um_pci_init_vqs()
544 dev->cmd_vq = vqs[0]; in um_pci_init_vqs()
545 dev->irq_vq = vqs[1]; in um_pci_init_vqs()
547 virtio_device_ready(dev->vdev); in um_pci_init_vqs()
553 um_pci_irq_vq_addbuf(dev->irq_vq, msg, false); in um_pci_init_vqs()
556 virtqueue_kick(dev->irq_vq); in um_pci_init_vqs()
564 int i, free = -1; in um_pci_virtio_probe()
565 int err = -ENOSPC; in um_pci_virtio_probe()
569 return -ENOMEM; in um_pci_virtio_probe()
571 dev->vdev = vdev; in um_pci_virtio_probe()
572 vdev->priv = dev; in um_pci_virtio_probe()
589 dev->irq = irq_alloc_desc(numa_node_id()); in um_pci_virtio_probe()
590 if (dev->irq < 0) { in um_pci_virtio_probe()
591 err = dev->irq; in um_pci_virtio_probe()
595 vdev->priv = dev; in um_pci_virtio_probe()
599 device_set_wakeup_enable(&vdev->dev, true); in um_pci_virtio_probe()
602 * In order to do suspend-resume properly, don't allow VQs in um_pci_virtio_probe()
611 vdev->config->del_vqs(vdev); in um_pci_virtio_probe()
620 struct um_pci_device *dev = vdev->priv; in um_pci_virtio_remove()
625 vdev->config->del_vqs(vdev); in um_pci_virtio_remove()
627 device_set_wakeup_enable(&vdev->dev, false); in um_pci_virtio_remove()
634 irq_free_desc(dev->irq); in um_pci_virtio_remove()
650 .driver.name = "virtio-pci",
659 .start = 0xf0000000 - MAX_DEVICES * CFG_SPACE_SIZE,
660 .end = 0xf0000000 - 1,
664 static long um_pci_map_cfgspace(unsigned long offset, size_t size, in um_pci_map_cfgspace() argument
668 if (WARN_ON(size > CFG_SPACE_SIZE || offset % CFG_SPACE_SIZE)) in um_pci_map_cfgspace()
669 return -EINVAL; in um_pci_map_cfgspace()
677 WARN(1, "cannot map offset 0x%lx/0x%zx\n", offset, size); in um_pci_map_cfgspace()
678 return -ENOENT; in um_pci_map_cfgspace()
694 size_t size; member
702 struct um_pci_map_iomem_data *data = _data; in um_pci_map_iomem_walk() local
703 struct um_pci_device_reg *reg = &um_pci_devices[pdev->devfn / 8]; in um_pci_map_iomem_walk()
707 if (!reg->dev) in um_pci_map_iomem_walk()
710 for (i = 0; i < ARRAY_SIZE(dev->resptr); i++) { in um_pci_map_iomem_walk()
711 struct resource *r = &pdev->resource[i]; in um_pci_map_iomem_walk()
713 if ((r->flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM) in um_pci_map_iomem_walk()
720 if (data->offset < r->start || data->offset > r->end) in um_pci_map_iomem_walk()
722 if (data->offset + data->size - 1 > r->end) in um_pci_map_iomem_walk()
725 dev = reg->dev; in um_pci_map_iomem_walk()
726 *data->ops = &um_pci_device_bar_ops; in um_pci_map_iomem_walk()
727 dev->resptr[i] = i; in um_pci_map_iomem_walk()
728 *data->priv = &dev->resptr[i]; in um_pci_map_iomem_walk()
729 data->ret = data->offset - r->start; in um_pci_map_iomem_walk()
738 static long um_pci_map_iomem(unsigned long offset, size_t size, in um_pci_map_iomem() argument
742 struct um_pci_map_iomem_data data = { in um_pci_map_iomem() local
745 .size = size, in um_pci_map_iomem()
748 .ret = -ENOENT, in um_pci_map_iomem()
751 pci_walk_bus(bridge->bus, um_pci_map_iomem_walk, &data); in um_pci_map_iomem()
752 return data.ret; in um_pci_map_iomem()
759 static void um_pci_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) in um_pci_compose_msi_msg() argument
763 * in UML, so we can simply map MSI(-X) vectors to there, it cannot be in um_pci_compose_msi_msg()
769 msg->address_hi = 0; in um_pci_compose_msi_msg()
770 msg->address_lo = 0xa0000; in um_pci_compose_msi_msg()
771 msg->data = data->irq; in um_pci_compose_msi_msg()
791 return -ENOSPC; in um_pci_inner_domain_alloc()
798 domain->host_data, handle_simple_irq, in um_pci_inner_domain_alloc()
811 if (!test_bit(d->hwirq, um_pci_msi_used)) in um_pci_inner_domain_free()
812 pr_err("trying to free unused MSI#%lu\n", d->hwirq); in um_pci_inner_domain_free()
814 __clear_bit(d->hwirq, um_pci_msi_used); in um_pci_inner_domain_free()
846 struct um_pci_device_reg *reg = &um_pci_devices[pdev->devfn / 8]; in um_pci_map_irq()
848 if (WARN_ON(!reg->dev)) in um_pci_map_irq()
849 return -EINVAL; in um_pci_map_irq()
852 return reg->dev->irq; in um_pci_map_irq()
870 "No virtio device ID configured for PCI - no PCI support\n")) in um_pci_init()
875 return -ENOMEM; in um_pci_init()
879 err = -ENOMEM; in um_pci_init()
883 um_pci_fwnode = irq_domain_alloc_named_fwnode("um-pci"); in um_pci_init()
885 err = -ENOMEM; in um_pci_init()
893 err = -ENOMEM; in um_pci_init()
901 err = -ENOMEM; in um_pci_init()
905 pci_add_resource(&bridge->windows, &virt_iomem_resource); in um_pci_init()
906 pci_add_resource(&bridge->windows, &busn_resource); in um_pci_init()
907 bridge->ops = &um_pci_ops; in um_pci_init()
908 bridge->map_irq = um_pci_map_irq; in um_pci_init()
916 err = -ENOMEM; in um_pci_init()
935 pci_free_resource_list(&bridge->windows); in um_pci_init()
948 pci_free_resource_list(&bridge->windows); in um_pci_exit()