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