Lines Matching refs:mdev_state

156 	struct mdev_state *mdev_state;
162 struct mdev_state {
203 static struct page *__mbochs_get_page(struct mdev_state *mdev_state,
205 static struct page *mbochs_get_page(struct mdev_state *mdev_state,
218 static void mbochs_create_config_space(struct mdev_state *mdev_state)
220 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID],
222 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_DEVICE_ID],
224 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_VENDOR_ID],
226 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_SUBSYSTEM_ID],
229 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_COMMAND],
231 STORE_LE16((u16 *) &mdev_state->vconfig[PCI_CLASS_DEVICE],
233 mdev_state->vconfig[PCI_CLASS_REVISION] = 0x01;
235 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_0],
239 mdev_state->bar_mask[0] = ~(mdev_state->memsize) + 1;
241 STORE_LE32((u32 *) &mdev_state->vconfig[PCI_BASE_ADDRESS_2],
244 mdev_state->bar_mask[2] = ~(MBOCHS_MMIO_BAR_SIZE) + 1;
247 static int mbochs_check_framebuffer(struct mdev_state *mdev_state,
250 struct device *dev = mdev_dev(mdev_state->mdev);
251 u16 *vbe = mdev_state->vbe;
254 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
286 if (mode->offset + mode->size > mdev_state->memsize) {
305 static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset,
308 struct device *dev = mdev_dev(mdev_state->mdev);
318 cfg_addr = (cfg_addr & mdev_state->bar_mask[index]);
326 cfg_addr |= (mdev_state->vconfig[offset] &
328 STORE_LE32(&mdev_state->vconfig[offset], cfg_addr);
333 static void handle_mmio_write(struct mdev_state *mdev_state, u16 offset,
336 struct device *dev = mdev_dev(mdev_state->mdev);
348 if (index < ARRAY_SIZE(mdev_state->vbe))
349 mdev_state->vbe[index] = reg16;
363 static void handle_mmio_read(struct mdev_state *mdev_state, u16 offset,
366 struct device *dev = mdev_dev(mdev_state->mdev);
373 edid = &mdev_state->edid_regs;
379 memcpy(buf, mdev_state->edid_blob + offset, count);
385 if (index < ARRAY_SIZE(mdev_state->vbe))
386 reg16 = mdev_state->vbe[index];
400 static void handle_edid_regs(struct mdev_state *mdev_state, u16 offset,
403 char *regs = (void *)&mdev_state->edid_regs;
405 if (offset + count > sizeof(mdev_state->edid_regs))
427 static void handle_edid_blob(struct mdev_state *mdev_state, u16 offset,
430 if (offset + count > mdev_state->edid_regs.edid_max_size)
433 memcpy(mdev_state->edid_blob + offset, buf, count);
435 memcpy(buf, mdev_state->edid_blob + offset, count);
441 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
448 mutex_lock(&mdev_state->ops_lock);
452 handle_pci_cfg_write(mdev_state, pos, buf, count);
454 memcpy(buf, (mdev_state->vconfig + pos), count);
461 handle_mmio_write(mdev_state, pos, buf, count);
463 handle_mmio_read(mdev_state, pos, buf, count);
470 handle_edid_regs(mdev_state, pos, buf, count, is_write);
473 handle_edid_blob(mdev_state, pos, buf, count, is_write);
478 MBOCHS_MEMORY_BAR_OFFSET + mdev_state->memsize) {
481 pg = __mbochs_get_page(mdev_state, pos >> PAGE_SHIFT);
501 mutex_unlock(&mdev_state->ops_lock);
508 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
509 u32 size64k = mdev_state->memsize / (64 * 1024);
512 for (i = 0; i < ARRAY_SIZE(mdev_state->vbe); i++)
513 mdev_state->vbe[i] = 0;
514 mdev_state->vbe[VBE_DISPI_INDEX_ID] = VBE_DISPI_ID5;
515 mdev_state->vbe[VBE_DISPI_INDEX_VIDEO_MEMORY_64K] = size64k;
523 struct mdev_state *mdev_state;
530 mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL);
531 if (mdev_state == NULL)
534 mdev_state->vconfig = kzalloc(MBOCHS_CONFIG_SPACE_SIZE, GFP_KERNEL);
535 if (mdev_state->vconfig == NULL)
538 mdev_state->memsize = type->mbytes * 1024 * 1024;
539 mdev_state->pagecount = mdev_state->memsize >> PAGE_SHIFT;
540 mdev_state->pages = kcalloc(mdev_state->pagecount,
543 if (!mdev_state->pages)
547 kobj->name, type->mbytes, mdev_state->pagecount);
549 mutex_init(&mdev_state->ops_lock);
550 mdev_state->mdev = mdev;
551 mdev_set_drvdata(mdev, mdev_state);
552 INIT_LIST_HEAD(&mdev_state->dmabufs);
553 mdev_state->next_id = 1;
555 mdev_state->type = type;
556 mdev_state->edid_regs.max_xres = type->max_x;
557 mdev_state->edid_regs.max_yres = type->max_y;
558 mdev_state->edid_regs.edid_offset = MBOCHS_EDID_BLOB_OFFSET;
559 mdev_state->edid_regs.edid_max_size = sizeof(mdev_state->edid_blob);
560 mbochs_create_config_space(mdev_state);
567 kfree(mdev_state->vconfig);
568 kfree(mdev_state);
574 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
576 mbochs_used_mbytes -= mdev_state->type->mbytes;
578 kfree(mdev_state->pages);
579 kfree(mdev_state->vconfig);
580 kfree(mdev_state);
700 static struct page *__mbochs_get_page(struct mdev_state *mdev_state,
703 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
705 if (!mdev_state->pages[pgoff]) {
706 mdev_state->pages[pgoff] =
708 if (!mdev_state->pages[pgoff])
712 get_page(mdev_state->pages[pgoff]);
713 return mdev_state->pages[pgoff];
716 static struct page *mbochs_get_page(struct mdev_state *mdev_state,
721 if (WARN_ON(pgoff >= mdev_state->pagecount))
724 mutex_lock(&mdev_state->ops_lock);
725 page = __mbochs_get_page(mdev_state, pgoff);
726 mutex_unlock(&mdev_state->ops_lock);
731 static void mbochs_put_pages(struct mdev_state *mdev_state)
733 struct device *dev = mdev_dev(mdev_state->mdev);
736 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
738 for (i = 0; i < mdev_state->pagecount; i++) {
739 if (!mdev_state->pages[i])
741 put_page(mdev_state->pages[i]);
742 mdev_state->pages[i] = NULL;
751 struct mdev_state *mdev_state = vma->vm_private_data;
754 if (page_offset >= mdev_state->pagecount)
757 vmf->page = mbochs_get_page(mdev_state, page_offset);
770 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
776 if (vma->vm_end - vma->vm_start > mdev_state->memsize)
782 vma->vm_private_data = mdev_state;
806 struct device *dev = mdev_dev(dmabuf->mdev_state->mdev);
821 struct device *dev = mdev_dev(dmabuf->mdev_state->mdev);
838 struct device *dev = mdev_dev(dmabuf->mdev_state->mdev);
867 struct device *dev = mdev_dev(dmabuf->mdev_state->mdev);
879 struct mdev_state *mdev_state = dmabuf->mdev_state;
880 struct device *dev = mdev_dev(mdev_state->mdev);
888 mutex_lock(&mdev_state->ops_lock);
892 mutex_unlock(&mdev_state->ops_lock);
902 static struct mbochs_dmabuf *mbochs_dmabuf_alloc(struct mdev_state *mdev_state,
908 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
915 dmabuf->id = mdev_state->next_id++;
924 dmabuf->pages[pg] = __mbochs_get_page(mdev_state,
930 dmabuf->mdev_state = mdev_state;
931 list_add(&dmabuf->next, &mdev_state->dmabufs);
946 mbochs_dmabuf_find_by_mode(struct mdev_state *mdev_state,
951 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
953 list_for_each_entry(dmabuf, &mdev_state->dmabufs, next)
961 mbochs_dmabuf_find_by_id(struct mdev_state *mdev_state, u32 id)
965 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
967 list_for_each_entry(dmabuf, &mdev_state->dmabufs, next)
976 struct mdev_state *mdev_state = dmabuf->mdev_state;
977 struct device *dev = mdev_dev(mdev_state->mdev);
981 WARN_ON(!mutex_is_locked(&mdev_state->ops_lock));
1009 struct mdev_state *mdev_state;
1011 mdev_state = mdev_get_drvdata(mdev);
1012 if (!mdev_state)
1027 region_info->size = mdev_state->memsize;
1080 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
1102 mutex_lock(&mdev_state->ops_lock);
1106 ret = mbochs_check_framebuffer(mdev_state, &mode);
1117 dmabuf = mbochs_dmabuf_find_by_mode(mdev_state, &mode);
1119 mbochs_dmabuf_alloc(mdev_state, &mode);
1121 mutex_unlock(&mdev_state->ops_lock);
1134 mdev_state->active_id != plane->dmabuf_id) {
1136 mdev_state->active_id, plane->dmabuf_id);
1137 mdev_state->active_id = plane->dmabuf_id;
1139 mutex_unlock(&mdev_state->ops_lock);
1146 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
1149 mutex_lock(&mdev_state->ops_lock);
1151 dmabuf = mbochs_dmabuf_find_by_id(mdev_state, id);
1153 mutex_unlock(&mdev_state->ops_lock);
1160 mutex_unlock(&mdev_state->ops_lock);
1296 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
1299 mutex_lock(&mdev_state->ops_lock);
1301 list_for_each_entry_safe(dmabuf, tmp, &mdev_state->dmabufs, next) {
1310 mbochs_put_pages(mdev_state);
1312 mutex_unlock(&mdev_state->ops_lock);
1321 struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
1323 return sprintf(buf, "%d MB\n", mdev_state->type->mbytes);