Lines Matching defs:mdev_state

96 struct mdev_state {
109 static void mdpy_create_config_space(struct mdev_state *mdev_state)
111 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID],
113 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_DEVICE_ID],
115 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_VENDOR_ID],
117 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_ID],
120 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_COMMAND],
122 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_STATUS],
124 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_CLASS_DEVICE],
126 mdev_state->vconfig[PCI_CLASS_REVISION] = 0x01;
128 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_0],
132 mdev_state->bar_mask = ~(mdev_state->memsize) + 1;
135 mdev_state->vconfig[PCI_CAPABILITY_LIST] = MDPY_VENDORCAP_OFFSET;
136 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 0] = 0x09; /* vendor cap */
137 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 1] = 0x00; /* next ptr */
138 mdev_state->vconfig[MDPY_VENDORCAP_OFFSET + 2] = MDPY_VENDORCAP_SIZE;
139 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_FORMAT_OFFSET],
140 mdev_state->type->format);
141 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_WIDTH_OFFSET],
142 mdev_state->type->width);
143 STORE_LE32((u32 *) &mdev_state->vconfig[MDPY_HEIGHT_OFFSET],
144 mdev_state->type->height);
147 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset,
150 struct device *dev = mdev_dev(mdev_state->mdev);
158 cfg_addr = (cfg_addr & mdev_state->bar_mask);
165 cfg_addr |= (mdev_state->vconfig[offset] &
167 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr);
172 static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf,
177 mutex_lock(&mdev_state->ops_lock);
181 handle_pci_cfg_write(mdev_state, pos, buf, count);
183 memcpy(buf, (mdev_state->vconfig + pos), count);
187 MDPY_MEMORY_BAR_OFFSET + mdev_state->memsize)) {
190 memcpy(mdev_state->memblk, buf, count);
192 memcpy(buf, mdev_state->memblk, count);
195 dev_info(mdev_state->vdev.dev,
206 mutex_unlock(&mdev_state->ops_lock);
211 static int mdpy_reset(struct mdev_state *mdev_state)
216 stride = mdev_state->type->width * mdev_state->type->bytepp;
217 for (i = 0; i < mdev_state->type->height; i++)
218 memset(mdev_state->memblk + i * stride,
219 i * 255 / mdev_state->type->height,
226 struct mdev_state *mdev_state =
227 container_of(vdev, struct mdev_state, vdev);
234 mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL);
235 if (!mdev_state->vconfig)
240 mdev_state->memblk = vmalloc_user(fbsize);
241 if (!mdev_state->memblk)
244 mutex_init(&mdev_state->ops_lock);
245 mdev_state->mdev = mdev;
246 mdev_state->type = type;
247 mdev_state->memsize = fbsize;
248 mdpy_create_config_space(mdev_state);
249 mdpy_reset(mdev_state);
256 kfree(mdev_state->vconfig);
262 struct mdev_state *mdev_state;
265 mdev_state = vfio_alloc_device(mdev_state, vdev, &mdev->dev,
267 if (IS_ERR(mdev_state))
268 return PTR_ERR(mdev_state);
270 ret = vfio_register_emulated_iommu_dev(&mdev_state->vdev);
273 dev_set_drvdata(&mdev->dev, mdev_state);
277 vfio_put_device(&mdev_state->vdev);
283 struct mdev_state *mdev_state =
284 container_of(vdev, struct mdev_state, vdev);
286 vfree(mdev_state->memblk);
287 kfree(mdev_state->vconfig);
292 struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev);
296 vfio_unregister_group_dev(&mdev_state->vdev);
297 vfio_put_device(&mdev_state->vdev);
303 struct mdev_state *mdev_state =
304 container_of(vdev, struct mdev_state, vdev);
314 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
326 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
338 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
364 struct mdev_state *mdev_state =
365 container_of(vdev, struct mdev_state, vdev);
378 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
390 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
402 ret = mdev_access(mdev_state, (char *)&val, sizeof(val),
422 struct mdev_state *mdev_state =
423 container_of(vdev, struct mdev_state, vdev);
429 if (vma->vm_end - vma->vm_start > mdev_state->memsize)
434 return remap_vmalloc_range(vma, mdev_state->memblk, 0);
437 static int mdpy_get_region_info(struct mdev_state *mdev_state,
455 region_info->size = mdev_state->memsize;
483 static int mdpy_query_gfx_plane(struct mdev_state *mdev_state,
496 plane->drm_format = mdev_state->type->format;
497 plane->width = mdev_state->type->width;
498 plane->height = mdev_state->type->height;
499 plane->stride = (mdev_state->type->width *
500 mdev_state->type->bytepp);
501 plane->size = mdev_state->memsize;
519 struct mdev_state *mdev_state =
520 container_of(vdev, struct mdev_state, vdev);
539 memcpy(&mdev_state->dev_info, &info, sizeof(info));
560 ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id,
581 (info.index >= mdev_state->dev_info.num_irqs))
607 ret = mdpy_query_gfx_plane(mdev_state, &plane);
621 return mdpy_reset(mdev_state);
630 struct mdev_state *mdev_state = dev_get_drvdata(dev);
633 mdev_state->type->width,
634 mdev_state->type->height);