Lines Matching refs:mdev_state

97 struct mdev_state {  struct
110 static void mdpy_create_config_space(struct mdev_state *mdev_state) in mdpy_create_config_space() argument
112 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID], in mdpy_create_config_space()
114 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_DEVICE_ID], in mdpy_create_config_space()
116 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_VENDOR_ID], in mdpy_create_config_space()
118 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_ID], in mdpy_create_config_space()
121 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_COMMAND], in mdpy_create_config_space()
123 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_STATUS], in mdpy_create_config_space()
125 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_CLASS_DEVICE], in mdpy_create_config_space()
127 mdev_state->vconfig[PCI_CLASS_REVISION] = 0x01; in mdpy_create_config_space()
129 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_0], in mdpy_create_config_space()
133 mdev_state->bar_mask = ~(mdev_state->memsize) + 1; in mdpy_create_config_space()
136 mdev_state->vconfig[PCI_CAPABILITY_LIST] = MDPY_VENDORCAP_OFFSET; in mdpy_create_config_space()
137 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 0] = 0x09; /* vendor cap */ in mdpy_create_config_space()
138 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 1] = 0x00; /* next ptr */ in mdpy_create_config_space()
139 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 2] = MDPY_VENDORCAP_SIZE; in mdpy_create_config_space()
140 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_FORMAT_OFFSET], in mdpy_create_config_space()
141 mdev_state->type->format); in mdpy_create_config_space()
142 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_WIDTH_OFFSET], in mdpy_create_config_space()
143 mdev_state->type->width); in mdpy_create_config_space()
144 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_HEIGHT_OFFSET], in mdpy_create_config_space()
145 mdev_state->type->height); in mdpy_create_config_space()
148 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, in handle_pci_cfg_write() argument
151 struct device *dev = mdev_dev(mdev_state->mdev); in handle_pci_cfg_write()
159 cfg_addr = (cfg_addr & mdev_state->bar_mask); in handle_pci_cfg_write()
166 cfg_addr |= (mdev_state->vconfig[offset] & in handle_pci_cfg_write()
168 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr); in handle_pci_cfg_write()
173 static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, in mdev_access() argument
178 mutex_lock(&mdev_state->ops_lock); in mdev_access()
182 handle_pci_cfg_write(mdev_state, pos, buf, count); in mdev_access()
184 memcpy(buf, (mdev_state->vconfig + pos), count); in mdev_access()
188 MDPY_MEMORY_BAR_OFFSET + mdev_state->memsize)) { in mdev_access()
191 memcpy(mdev_state->memblk, buf, count); in mdev_access()
193 memcpy(buf, mdev_state->memblk, count); in mdev_access()
196 dev_info(mdev_state->vdev.dev, in mdev_access()
207 mutex_unlock(&mdev_state->ops_lock); in mdev_access()
212 static int mdpy_reset(struct mdev_state *mdev_state) in mdpy_reset() argument
217 stride = mdev_state->type->width * mdev_state->type->bytepp; in mdpy_reset()
218 for (i = 0; i < mdev_state->type->height; i++) in mdpy_reset()
219 memset(mdev_state->memblk + i * stride, in mdpy_reset()
220 i * 255 / mdev_state->type->height, in mdpy_reset()
227 struct mdev_state *mdev_state = in mdpy_init_dev() local
228 container_of(vdev, struct mdev_state, vdev); in mdpy_init_dev()
235 mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); in mdpy_init_dev()
236 if (!mdev_state->vconfig) in mdpy_init_dev()
241 mdev_state->memblk = vmalloc_user(fbsize); in mdpy_init_dev()
242 if (!mdev_state->memblk) in mdpy_init_dev()
245 mutex_init(&mdev_state->ops_lock); in mdpy_init_dev()
246 mdev_state->mdev = mdev; in mdpy_init_dev()
247 mdev_state->type = type; in mdpy_init_dev()
248 mdev_state->memsize = fbsize; in mdpy_init_dev()
249 mdpy_create_config_space(mdev_state); in mdpy_init_dev()
250 mdpy_reset(mdev_state); in mdpy_init_dev()
257 kfree(mdev_state->vconfig); in mdpy_init_dev()
263 struct mdev_state *mdev_state; in mdpy_probe() local
266 mdev_state = vfio_alloc_device(mdev_state, vdev, &mdev->dev, in mdpy_probe()
268 if (IS_ERR(mdev_state)) in mdpy_probe()
269 return PTR_ERR(mdev_state); in mdpy_probe()
271 ret = vfio_register_emulated_iommu_dev(&mdev_state->vdev); in mdpy_probe()
274 dev_set_drvdata(&mdev->dev, mdev_state); in mdpy_probe()
278 vfio_put_device(&mdev_state->vdev); in mdpy_probe()
284 struct mdev_state *mdev_state = in mdpy_release_dev() local
285 container_of(vdev, struct mdev_state, vdev); in mdpy_release_dev()
287 vfree(mdev_state->memblk); in mdpy_release_dev()
288 kfree(mdev_state->vconfig); in mdpy_release_dev()
293 struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); in mdpy_remove() local
297 vfio_unregister_group_dev(&mdev_state->vdev); in mdpy_remove()
298 vfio_put_device(&mdev_state->vdev); in mdpy_remove()
304 struct mdev_state *mdev_state = in mdpy_read() local
305 container_of(vdev, struct mdev_state, vdev); in mdpy_read()
315 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
327 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
339 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_read()
365 struct mdev_state *mdev_state = in mdpy_write() local
366 container_of(vdev, struct mdev_state, vdev); in mdpy_write()
379 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
391 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
403 ret = mdev_access(mdev_state, (char *)&val, sizeof(val), in mdpy_write()
423 struct mdev_state *mdev_state = in mdpy_mmap() local
424 container_of(vdev, struct mdev_state, vdev); in mdpy_mmap()
430 if (vma->vm_end - vma->vm_start > mdev_state->memsize) in mdpy_mmap()
435 return remap_vmalloc_range(vma, mdev_state->memblk, 0); in mdpy_mmap()
438 static int mdpy_get_region_info(struct mdev_state *mdev_state, in mdpy_get_region_info() argument
456 region_info->size = mdev_state->memsize; in mdpy_get_region_info()
484 static int mdpy_query_gfx_plane(struct mdev_state *mdev_state, in mdpy_query_gfx_plane() argument
497 plane->drm_format = mdev_state->type->format; in mdpy_query_gfx_plane()
498 plane->width = mdev_state->type->width; in mdpy_query_gfx_plane()
499 plane->height = mdev_state->type->height; in mdpy_query_gfx_plane()
500 plane->stride = (mdev_state->type->width * in mdpy_query_gfx_plane()
501 mdev_state->type->bytepp); in mdpy_query_gfx_plane()
502 plane->size = mdev_state->memsize; in mdpy_query_gfx_plane()
520 struct mdev_state *mdev_state = in mdpy_ioctl() local
521 container_of(vdev, struct mdev_state, vdev); in mdpy_ioctl()
540 memcpy(&mdev_state->dev_info, &info, sizeof(info)); in mdpy_ioctl()
561 ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, in mdpy_ioctl()
582 (info.index >= mdev_state->dev_info.num_irqs)) in mdpy_ioctl()
608 ret = mdpy_query_gfx_plane(mdev_state, &plane); in mdpy_ioctl()
622 return mdpy_reset(mdev_state); in mdpy_ioctl()
631 struct mdev_state *mdev_state = dev_get_drvdata(dev); in resolution_show() local
634 mdev_state->type->width, in resolution_show()
635 mdev_state->type->height); in resolution_show()