Lines Matching refs:mdev_state
91 struct mdev_state { struct
104 static void mdpy_create_config_space(struct mdev_state *mdev_state) in mdpy_create_config_space() argument
106 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID], in mdpy_create_config_space()
108 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_DEVICE_ID], in mdpy_create_config_space()
110 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_VENDOR_ID], in mdpy_create_config_space()
112 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_ID], in mdpy_create_config_space()
115 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_COMMAND], in mdpy_create_config_space()
117 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_STATUS], in mdpy_create_config_space()
119 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_CLASS_DEVICE], in mdpy_create_config_space()
121 mdev_state->vconfig[PCI_CLASS_REVISION] = 0x01; in mdpy_create_config_space()
123 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_0], in mdpy_create_config_space()
127 mdev_state->bar_mask = ~(mdev_state->memsize) + 1; in mdpy_create_config_space()
130 mdev_state->vconfig[PCI_CAPABILITY_LIST] = MDPY_VENDORCAP_OFFSET; in mdpy_create_config_space()
131 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 0] = 0x09; /* vendor cap */ in mdpy_create_config_space()
132 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 1] = 0x00; /* next ptr */ in mdpy_create_config_space()
133 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 2] = MDPY_VENDORCAP_SIZE; in mdpy_create_config_space()
134 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_FORMAT_OFFSET], in mdpy_create_config_space()
135 mdev_state->type->format); in mdpy_create_config_space()
136 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_WIDTH_OFFSET], in mdpy_create_config_space()
137 mdev_state->type->width); in mdpy_create_config_space()
138 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_HEIGHT_OFFSET], in mdpy_create_config_space()
139 mdev_state->type->height); in mdpy_create_config_space()
142 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, in handle_pci_cfg_write() argument
145 struct device *dev = mdev_dev(mdev_state->mdev); in handle_pci_cfg_write()
153 cfg_addr = (cfg_addr & mdev_state->bar_mask); in handle_pci_cfg_write()
160 cfg_addr |= (mdev_state->vconfig[offset] & in handle_pci_cfg_write()
162 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr); in handle_pci_cfg_write()
167 static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, in mdev_access() argument
172 mutex_lock(&mdev_state->ops_lock); in mdev_access()
176 handle_pci_cfg_write(mdev_state, pos, buf, count); in mdev_access()
178 memcpy(buf, (mdev_state->vconfig + pos), count); in mdev_access()
182 MDPY_MEMORY_BAR_OFFSET + mdev_state->memsize)) { in mdev_access()
185 memcpy(mdev_state->memblk, buf, count); in mdev_access()
187 memcpy(buf, mdev_state->memblk, count); in mdev_access()
190 dev_info(mdev_state->vdev.dev, in mdev_access()
201 mutex_unlock(&mdev_state->ops_lock); in mdev_access()
206 static int mdpy_reset(struct mdev_state *mdev_state) in mdpy_reset() argument
211 stride = mdev_state->type->width * mdev_state->type->bytepp; in mdpy_reset()
212 for (i = 0; i < mdev_state->type->height; i++) in mdpy_reset()
213 memset(mdev_state->memblk + i * stride, in mdpy_reset()
214 i * 255 / mdev_state->type->height, in mdpy_reset()
224 struct mdev_state *mdev_state; in mdpy_probe() local
231 mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); in mdpy_probe()
232 if (mdev_state == NULL) in mdpy_probe()
234 vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mdpy_dev_ops); in mdpy_probe()
236 mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); in mdpy_probe()
237 if (mdev_state->vconfig == NULL) { in mdpy_probe()
244 mdev_state->memblk = vmalloc_user(fbsize); in mdpy_probe()
245 if (!mdev_state->memblk) { in mdpy_probe()
252 mutex_init(&mdev_state->ops_lock); in mdpy_probe()
253 mdev_state->mdev = mdev; in mdpy_probe()
254 mdev_state->type = type; in mdpy_probe()
255 mdev_state->memsize = fbsize; in mdpy_probe()
256 mdpy_create_config_space(mdev_state); in mdpy_probe()
257 mdpy_reset(mdev_state); in mdpy_probe()
261 ret = vfio_register_group_dev(&mdev_state->vdev); in mdpy_probe()
264 dev_set_drvdata(&mdev->dev, mdev_state); in mdpy_probe()
267 vfree(mdev_state->memblk); in mdpy_probe()
269 kfree(mdev_state->vconfig); in mdpy_probe()
271 vfio_uninit_group_dev(&mdev_state->vdev); in mdpy_probe()
272 kfree(mdev_state); in mdpy_probe()
278 struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); in mdpy_remove() local
282 vfio_unregister_group_dev(&mdev_state->vdev); in mdpy_remove()
283 vfree(mdev_state->memblk); in mdpy_remove()
284 kfree(mdev_state->vconfig); in mdpy_remove()
285 vfio_uninit_group_dev(&mdev_state->vdev); in mdpy_remove()
286 kfree(mdev_state); in mdpy_remove()
294 struct mdev_state *mdev_state = in mdpy_read() local
295 container_of(vdev, struct mdev_state, vdev); in mdpy_read()
305 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
317 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
329 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
355 struct mdev_state *mdev_state = in mdpy_write() local
356 container_of(vdev, struct mdev_state, vdev); in mdpy_write()
369 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
381 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
393 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
413 struct mdev_state *mdev_state = in mdpy_mmap() local
414 container_of(vdev, struct mdev_state, vdev); in mdpy_mmap()
420 if (vma->vm_end - vma->vm_start > mdev_state->memsize) in mdpy_mmap()
425 return remap_vmalloc_range(vma, mdev_state->memblk, 0); in mdpy_mmap()
428 static int mdpy_get_region_info(struct mdev_state *mdev_state, in mdpy_get_region_info() argument
446 region_info->size = mdev_state->memsize; in mdpy_get_region_info()
474 static int mdpy_query_gfx_plane(struct mdev_state *mdev_state, in mdpy_query_gfx_plane() argument
487 plane->drm_format = mdev_state->type->format; in mdpy_query_gfx_plane()
488 plane->width = mdev_state->type->width; in mdpy_query_gfx_plane()
489 plane->height = mdev_state->type->height; in mdpy_query_gfx_plane()
490 plane->stride = (mdev_state->type->width * in mdpy_query_gfx_plane()
491 mdev_state->type->bytepp); in mdpy_query_gfx_plane()
492 plane->size = mdev_state->memsize; in mdpy_query_gfx_plane()
510 struct mdev_state *mdev_state = in mdpy_ioctl() local
511 container_of(vdev, struct mdev_state, vdev); in mdpy_ioctl()
530 memcpy(&mdev_state->dev_info, &info, sizeof(info)); in mdpy_ioctl()
551 ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, in mdpy_ioctl()
572 (info.index >= mdev_state->dev_info.num_irqs)) in mdpy_ioctl()
598 ret = mdpy_query_gfx_plane(mdev_state, &plane); in mdpy_ioctl()
612 return mdpy_reset(mdev_state); in mdpy_ioctl()
621 struct mdev_state *mdev_state = dev_get_drvdata(dev); in resolution_show() local
624 mdev_state->type->width, in resolution_show()
625 mdev_state->type->height); in resolution_show()