Lines Matching refs:mdev_state
94 struct mdev_state { struct
107 static void mdpy_create_config_space(struct mdev_state *mdev_state) in mdpy_create_config_space() argument
109 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID], in mdpy_create_config_space()
111 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_DEVICE_ID], in mdpy_create_config_space()
113 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_VENDOR_ID], in mdpy_create_config_space()
115 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_ID], in mdpy_create_config_space()
118 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_COMMAND], in mdpy_create_config_space()
120 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_STATUS], in mdpy_create_config_space()
122 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_CLASS_DEVICE], in mdpy_create_config_space()
124 mdev_state->vconfig[PCI_CLASS_REVISION] = 0x01; in mdpy_create_config_space()
126 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_0], in mdpy_create_config_space()
130 mdev_state->bar_mask = ~(mdev_state->memsize) + 1; in mdpy_create_config_space()
133 mdev_state->vconfig[PCI_CAPABILITY_LIST] = MDPY_VENDORCAP_OFFSET; in mdpy_create_config_space()
134 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 0] = 0x09; /* vendor cap */ in mdpy_create_config_space()
135 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 1] = 0x00; /* next ptr */ in mdpy_create_config_space()
136 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 2] = MDPY_VENDORCAP_SIZE; in mdpy_create_config_space()
137 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_FORMAT_OFFSET], in mdpy_create_config_space()
138 mdev_state->type->format); in mdpy_create_config_space()
139 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_WIDTH_OFFSET], in mdpy_create_config_space()
140 mdev_state->type->width); in mdpy_create_config_space()
141 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_HEIGHT_OFFSET], in mdpy_create_config_space()
142 mdev_state->type->height); in mdpy_create_config_space()
145 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, in handle_pci_cfg_write() argument
148 struct device *dev = mdev_dev(mdev_state->mdev); in handle_pci_cfg_write()
156 cfg_addr = (cfg_addr & mdev_state->bar_mask); in handle_pci_cfg_write()
163 cfg_addr |= (mdev_state->vconfig[offset] & in handle_pci_cfg_write()
165 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr); in handle_pci_cfg_write()
170 static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, in mdev_access() argument
175 mutex_lock(&mdev_state->ops_lock); in mdev_access()
179 handle_pci_cfg_write(mdev_state, pos, buf, count); in mdev_access()
181 memcpy(buf, (mdev_state->vconfig + pos), count); in mdev_access()
185 MDPY_MEMORY_BAR_OFFSET + mdev_state->memsize)) { in mdev_access()
188 memcpy(mdev_state->memblk, buf, count); in mdev_access()
190 memcpy(buf, mdev_state->memblk, count); in mdev_access()
193 dev_info(mdev_state->vdev.dev, in mdev_access()
204 mutex_unlock(&mdev_state->ops_lock); in mdev_access()
209 static int mdpy_reset(struct mdev_state *mdev_state) in mdpy_reset() argument
214 stride = mdev_state->type->width * mdev_state->type->bytepp; in mdpy_reset()
215 for (i = 0; i < mdev_state->type->height; i++) in mdpy_reset()
216 memset(mdev_state->memblk + i * stride, in mdpy_reset()
217 i * 255 / mdev_state->type->height, in mdpy_reset()
224 struct mdev_state *mdev_state = in mdpy_init_dev() local
225 container_of(vdev, struct mdev_state, vdev); in mdpy_init_dev()
232 mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); in mdpy_init_dev()
233 if (!mdev_state->vconfig) in mdpy_init_dev()
238 mdev_state->memblk = vmalloc_user(fbsize); in mdpy_init_dev()
239 if (!mdev_state->memblk) in mdpy_init_dev()
242 mutex_init(&mdev_state->ops_lock); in mdpy_init_dev()
243 mdev_state->mdev = mdev; in mdpy_init_dev()
244 mdev_state->type = type; in mdpy_init_dev()
245 mdev_state->memsize = fbsize; in mdpy_init_dev()
246 mdpy_create_config_space(mdev_state); in mdpy_init_dev()
247 mdpy_reset(mdev_state); in mdpy_init_dev()
254 kfree(mdev_state->vconfig); in mdpy_init_dev()
260 struct mdev_state *mdev_state; in mdpy_probe() local
263 mdev_state = vfio_alloc_device(mdev_state, vdev, &mdev->dev, in mdpy_probe()
265 if (IS_ERR(mdev_state)) in mdpy_probe()
266 return PTR_ERR(mdev_state); in mdpy_probe()
268 ret = vfio_register_emulated_iommu_dev(&mdev_state->vdev); in mdpy_probe()
271 dev_set_drvdata(&mdev->dev, mdev_state); in mdpy_probe()
275 vfio_put_device(&mdev_state->vdev); in mdpy_probe()
281 struct mdev_state *mdev_state = in mdpy_release_dev() local
282 container_of(vdev, struct mdev_state, vdev); in mdpy_release_dev()
284 vfree(mdev_state->memblk); in mdpy_release_dev()
285 kfree(mdev_state->vconfig); in mdpy_release_dev()
290 struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); in mdpy_remove() local
294 vfio_unregister_group_dev(&mdev_state->vdev); in mdpy_remove()
295 vfio_put_device(&mdev_state->vdev); in mdpy_remove()
301 struct mdev_state *mdev_state = in mdpy_read() local
302 container_of(vdev, struct mdev_state, vdev); in mdpy_read()
312 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
324 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
336 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
362 struct mdev_state *mdev_state = in mdpy_write() local
363 container_of(vdev, struct mdev_state, vdev); in mdpy_write()
376 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
388 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
400 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
420 struct mdev_state *mdev_state = in mdpy_mmap() local
421 container_of(vdev, struct mdev_state, vdev); in mdpy_mmap()
427 if (vma->vm_end - vma->vm_start > mdev_state->memsize) in mdpy_mmap()
432 return remap_vmalloc_range(vma, mdev_state->memblk, 0); in mdpy_mmap()
435 static int mdpy_get_region_info(struct mdev_state *mdev_state, in mdpy_get_region_info() argument
453 region_info->size = mdev_state->memsize; in mdpy_get_region_info()
481 static int mdpy_query_gfx_plane(struct mdev_state *mdev_state, in mdpy_query_gfx_plane() argument
494 plane->drm_format = mdev_state->type->format; in mdpy_query_gfx_plane()
495 plane->width = mdev_state->type->width; in mdpy_query_gfx_plane()
496 plane->height = mdev_state->type->height; in mdpy_query_gfx_plane()
497 plane->stride = (mdev_state->type->width * in mdpy_query_gfx_plane()
498 mdev_state->type->bytepp); in mdpy_query_gfx_plane()
499 plane->size = mdev_state->memsize; in mdpy_query_gfx_plane()
517 struct mdev_state *mdev_state = in mdpy_ioctl() local
518 container_of(vdev, struct mdev_state, vdev); in mdpy_ioctl()
537 memcpy(&mdev_state->dev_info, &info, sizeof(info)); in mdpy_ioctl()
558 ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, in mdpy_ioctl()
579 (info.index >= mdev_state->dev_info.num_irqs)) in mdpy_ioctl()
605 ret = mdpy_query_gfx_plane(mdev_state, &plane); in mdpy_ioctl()
619 return mdpy_reset(mdev_state); in mdpy_ioctl()
628 struct mdev_state *mdev_state = dev_get_drvdata(dev); in resolution_show() local
631 mdev_state->type->width, in resolution_show()
632 mdev_state->type->height); in resolution_show()