1 // SPDX-License-Identifier: GPL-2.0 OR MIT
4 * Xen para-virtual DRM device
6 * Copyright (C) 2016-2018 EPAM Systems Inc.
8 * Author: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
11 #include <linux/delay.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/module.h>
14 #include <linux/of_device.h>
16 #include <drm/drm_atomic_helper.h>
17 #include <drm/drm_drv.h>
18 #include <drm/drm_ioctl.h>
19 #include <drm/drm_probe_helper.h>
20 #include <drm/drm_file.h>
21 #include <drm/drm_gem.h>
23 #include <xen/platform_pci.h>
25 #include <xen/xenbus.h>
27 #include <xen/xen-front-pgdir-shbuf.h>
28 #include <xen/interface/io/displif.h>
30 #include "xen_drm_front.h"
31 #include "xen_drm_front_cfg.h"
32 #include "xen_drm_front_evtchnl.h"
33 #include "xen_drm_front_gem.h"
34 #include "xen_drm_front_kms.h"
36 struct xen_drm_front_dbuf
{
37 struct list_head list
;
41 struct xen_front_pgdir_shbuf shbuf
;
44 static void dbuf_add_to_list(struct xen_drm_front_info
*front_info
,
45 struct xen_drm_front_dbuf
*dbuf
, u64 dbuf_cookie
)
47 dbuf
->dbuf_cookie
= dbuf_cookie
;
48 list_add(&dbuf
->list
, &front_info
->dbuf_list
);
51 static struct xen_drm_front_dbuf
*dbuf_get(struct list_head
*dbuf_list
,
54 struct xen_drm_front_dbuf
*buf
, *q
;
56 list_for_each_entry_safe(buf
, q
, dbuf_list
, list
)
57 if (buf
->dbuf_cookie
== dbuf_cookie
)
63 static void dbuf_free(struct list_head
*dbuf_list
, u64 dbuf_cookie
)
65 struct xen_drm_front_dbuf
*buf
, *q
;
67 list_for_each_entry_safe(buf
, q
, dbuf_list
, list
)
68 if (buf
->dbuf_cookie
== dbuf_cookie
) {
70 xen_front_pgdir_shbuf_unmap(&buf
->shbuf
);
71 xen_front_pgdir_shbuf_free(&buf
->shbuf
);
77 static void dbuf_free_all(struct list_head
*dbuf_list
)
79 struct xen_drm_front_dbuf
*buf
, *q
;
81 list_for_each_entry_safe(buf
, q
, dbuf_list
, list
) {
83 xen_front_pgdir_shbuf_unmap(&buf
->shbuf
);
84 xen_front_pgdir_shbuf_free(&buf
->shbuf
);
89 static struct xendispl_req
*
90 be_prepare_req(struct xen_drm_front_evtchnl
*evtchnl
, u8 operation
)
92 struct xendispl_req
*req
;
94 req
= RING_GET_REQUEST(&evtchnl
->u
.req
.ring
,
95 evtchnl
->u
.req
.ring
.req_prod_pvt
);
96 req
->operation
= operation
;
97 req
->id
= evtchnl
->evt_next_id
++;
98 evtchnl
->evt_id
= req
->id
;
102 static int be_stream_do_io(struct xen_drm_front_evtchnl
*evtchnl
,
103 struct xendispl_req
*req
)
105 reinit_completion(&evtchnl
->u
.req
.completion
);
106 if (unlikely(evtchnl
->state
!= EVTCHNL_STATE_CONNECTED
))
109 xen_drm_front_evtchnl_flush(evtchnl
);
113 static int be_stream_wait_io(struct xen_drm_front_evtchnl
*evtchnl
)
115 if (wait_for_completion_timeout(&evtchnl
->u
.req
.completion
,
116 msecs_to_jiffies(XEN_DRM_FRONT_WAIT_BACK_MS
)) <= 0)
119 return evtchnl
->u
.req
.resp_status
;
122 int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline
*pipeline
,
123 u32 x
, u32 y
, u32 width
, u32 height
,
124 u32 bpp
, u64 fb_cookie
)
126 struct xen_drm_front_evtchnl
*evtchnl
;
127 struct xen_drm_front_info
*front_info
;
128 struct xendispl_req
*req
;
132 front_info
= pipeline
->drm_info
->front_info
;
133 evtchnl
= &front_info
->evt_pairs
[pipeline
->index
].req
;
134 if (unlikely(!evtchnl
))
137 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
139 spin_lock_irqsave(&front_info
->io_lock
, flags
);
140 req
= be_prepare_req(evtchnl
, XENDISPL_OP_SET_CONFIG
);
141 req
->op
.set_config
.x
= x
;
142 req
->op
.set_config
.y
= y
;
143 req
->op
.set_config
.width
= width
;
144 req
->op
.set_config
.height
= height
;
145 req
->op
.set_config
.bpp
= bpp
;
146 req
->op
.set_config
.fb_cookie
= fb_cookie
;
148 ret
= be_stream_do_io(evtchnl
, req
);
149 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
152 ret
= be_stream_wait_io(evtchnl
);
154 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
158 int xen_drm_front_dbuf_create(struct xen_drm_front_info
*front_info
,
159 u64 dbuf_cookie
, u32 width
, u32 height
,
160 u32 bpp
, u64 size
, struct page
**pages
)
162 struct xen_drm_front_evtchnl
*evtchnl
;
163 struct xen_drm_front_dbuf
*dbuf
;
164 struct xendispl_req
*req
;
165 struct xen_front_pgdir_shbuf_cfg buf_cfg
;
169 evtchnl
= &front_info
->evt_pairs
[GENERIC_OP_EVT_CHNL
].req
;
170 if (unlikely(!evtchnl
))
173 dbuf
= kzalloc(sizeof(*dbuf
), GFP_KERNEL
);
177 dbuf_add_to_list(front_info
, dbuf
, dbuf_cookie
);
179 memset(&buf_cfg
, 0, sizeof(buf_cfg
));
180 buf_cfg
.xb_dev
= front_info
->xb_dev
;
181 buf_cfg
.num_pages
= DIV_ROUND_UP(size
, PAGE_SIZE
);
182 buf_cfg
.pages
= pages
;
183 buf_cfg
.pgdir
= &dbuf
->shbuf
;
184 buf_cfg
.be_alloc
= front_info
->cfg
.be_alloc
;
186 ret
= xen_front_pgdir_shbuf_alloc(&buf_cfg
);
188 goto fail_shbuf_alloc
;
190 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
192 spin_lock_irqsave(&front_info
->io_lock
, flags
);
193 req
= be_prepare_req(evtchnl
, XENDISPL_OP_DBUF_CREATE
);
194 req
->op
.dbuf_create
.gref_directory
=
195 xen_front_pgdir_shbuf_get_dir_start(&dbuf
->shbuf
);
196 req
->op
.dbuf_create
.buffer_sz
= size
;
197 req
->op
.dbuf_create
.dbuf_cookie
= dbuf_cookie
;
198 req
->op
.dbuf_create
.width
= width
;
199 req
->op
.dbuf_create
.height
= height
;
200 req
->op
.dbuf_create
.bpp
= bpp
;
201 if (buf_cfg
.be_alloc
)
202 req
->op
.dbuf_create
.flags
|= XENDISPL_DBUF_FLG_REQ_ALLOC
;
204 ret
= be_stream_do_io(evtchnl
, req
);
205 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
210 ret
= be_stream_wait_io(evtchnl
);
214 ret
= xen_front_pgdir_shbuf_map(&dbuf
->shbuf
);
218 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
222 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
224 dbuf_free(&front_info
->dbuf_list
, dbuf_cookie
);
228 static int xen_drm_front_dbuf_destroy(struct xen_drm_front_info
*front_info
,
231 struct xen_drm_front_evtchnl
*evtchnl
;
232 struct xendispl_req
*req
;
237 evtchnl
= &front_info
->evt_pairs
[GENERIC_OP_EVT_CHNL
].req
;
238 if (unlikely(!evtchnl
))
241 be_alloc
= front_info
->cfg
.be_alloc
;
244 * For the backend allocated buffer release references now, so backend
245 * can free the buffer.
248 dbuf_free(&front_info
->dbuf_list
, dbuf_cookie
);
250 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
252 spin_lock_irqsave(&front_info
->io_lock
, flags
);
253 req
= be_prepare_req(evtchnl
, XENDISPL_OP_DBUF_DESTROY
);
254 req
->op
.dbuf_destroy
.dbuf_cookie
= dbuf_cookie
;
256 ret
= be_stream_do_io(evtchnl
, req
);
257 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
260 ret
= be_stream_wait_io(evtchnl
);
263 * Do this regardless of communication status with the backend:
264 * if we cannot remove remote resources remove what we can locally.
267 dbuf_free(&front_info
->dbuf_list
, dbuf_cookie
);
269 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
273 int xen_drm_front_fb_attach(struct xen_drm_front_info
*front_info
,
274 u64 dbuf_cookie
, u64 fb_cookie
, u32 width
,
275 u32 height
, u32 pixel_format
)
277 struct xen_drm_front_evtchnl
*evtchnl
;
278 struct xen_drm_front_dbuf
*buf
;
279 struct xendispl_req
*req
;
283 evtchnl
= &front_info
->evt_pairs
[GENERIC_OP_EVT_CHNL
].req
;
284 if (unlikely(!evtchnl
))
287 buf
= dbuf_get(&front_info
->dbuf_list
, dbuf_cookie
);
291 buf
->fb_cookie
= fb_cookie
;
293 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
295 spin_lock_irqsave(&front_info
->io_lock
, flags
);
296 req
= be_prepare_req(evtchnl
, XENDISPL_OP_FB_ATTACH
);
297 req
->op
.fb_attach
.dbuf_cookie
= dbuf_cookie
;
298 req
->op
.fb_attach
.fb_cookie
= fb_cookie
;
299 req
->op
.fb_attach
.width
= width
;
300 req
->op
.fb_attach
.height
= height
;
301 req
->op
.fb_attach
.pixel_format
= pixel_format
;
303 ret
= be_stream_do_io(evtchnl
, req
);
304 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
307 ret
= be_stream_wait_io(evtchnl
);
309 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
313 int xen_drm_front_fb_detach(struct xen_drm_front_info
*front_info
,
316 struct xen_drm_front_evtchnl
*evtchnl
;
317 struct xendispl_req
*req
;
321 evtchnl
= &front_info
->evt_pairs
[GENERIC_OP_EVT_CHNL
].req
;
322 if (unlikely(!evtchnl
))
325 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
327 spin_lock_irqsave(&front_info
->io_lock
, flags
);
328 req
= be_prepare_req(evtchnl
, XENDISPL_OP_FB_DETACH
);
329 req
->op
.fb_detach
.fb_cookie
= fb_cookie
;
331 ret
= be_stream_do_io(evtchnl
, req
);
332 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
335 ret
= be_stream_wait_io(evtchnl
);
337 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
341 int xen_drm_front_page_flip(struct xen_drm_front_info
*front_info
,
342 int conn_idx
, u64 fb_cookie
)
344 struct xen_drm_front_evtchnl
*evtchnl
;
345 struct xendispl_req
*req
;
349 if (unlikely(conn_idx
>= front_info
->num_evt_pairs
))
352 evtchnl
= &front_info
->evt_pairs
[conn_idx
].req
;
354 mutex_lock(&evtchnl
->u
.req
.req_io_lock
);
356 spin_lock_irqsave(&front_info
->io_lock
, flags
);
357 req
= be_prepare_req(evtchnl
, XENDISPL_OP_PG_FLIP
);
358 req
->op
.pg_flip
.fb_cookie
= fb_cookie
;
360 ret
= be_stream_do_io(evtchnl
, req
);
361 spin_unlock_irqrestore(&front_info
->io_lock
, flags
);
364 ret
= be_stream_wait_io(evtchnl
);
366 mutex_unlock(&evtchnl
->u
.req
.req_io_lock
);
370 void xen_drm_front_on_frame_done(struct xen_drm_front_info
*front_info
,
371 int conn_idx
, u64 fb_cookie
)
373 struct xen_drm_front_drm_info
*drm_info
= front_info
->drm_info
;
375 if (unlikely(conn_idx
>= front_info
->cfg
.num_connectors
))
378 xen_drm_front_kms_on_frame_done(&drm_info
->pipeline
[conn_idx
],
382 static int xen_drm_drv_dumb_create(struct drm_file
*filp
,
383 struct drm_device
*dev
,
384 struct drm_mode_create_dumb
*args
)
386 struct xen_drm_front_drm_info
*drm_info
= dev
->dev_private
;
387 struct drm_gem_object
*obj
;
391 * Dumb creation is a two stage process: first we create a fully
392 * constructed GEM object which is communicated to the backend, and
393 * only after that we can create GEM's handle. This is done so,
394 * because of the possible races: once you create a handle it becomes
395 * immediately visible to user-space, so the latter can try accessing
396 * object without pages etc.
397 * For details also see drm_gem_handle_create
399 args
->pitch
= DIV_ROUND_UP(args
->width
* args
->bpp
, 8);
400 args
->size
= args
->pitch
* args
->height
;
402 obj
= xen_drm_front_gem_create(dev
, args
->size
);
403 if (IS_ERR_OR_NULL(obj
)) {
408 ret
= xen_drm_front_dbuf_create(drm_info
->front_info
,
409 xen_drm_front_dbuf_to_cookie(obj
),
410 args
->width
, args
->height
, args
->bpp
,
412 xen_drm_front_gem_get_pages(obj
));
416 /* This is the tail of GEM object creation */
417 ret
= drm_gem_handle_create(filp
, obj
, &args
->handle
);
421 /* Drop reference from allocate - handle holds it now */
422 drm_gem_object_put_unlocked(obj
);
426 xen_drm_front_dbuf_destroy(drm_info
->front_info
,
427 xen_drm_front_dbuf_to_cookie(obj
));
429 /* drop reference from allocate */
430 drm_gem_object_put_unlocked(obj
);
432 DRM_ERROR("Failed to create dumb buffer: %d\n", ret
);
436 static void xen_drm_drv_free_object_unlocked(struct drm_gem_object
*obj
)
438 struct xen_drm_front_drm_info
*drm_info
= obj
->dev
->dev_private
;
441 if (drm_dev_enter(obj
->dev
, &idx
)) {
442 xen_drm_front_dbuf_destroy(drm_info
->front_info
,
443 xen_drm_front_dbuf_to_cookie(obj
));
446 dbuf_free(&drm_info
->front_info
->dbuf_list
,
447 xen_drm_front_dbuf_to_cookie(obj
));
450 xen_drm_front_gem_free_object_unlocked(obj
);
453 static void xen_drm_drv_release(struct drm_device
*dev
)
455 struct xen_drm_front_drm_info
*drm_info
= dev
->dev_private
;
456 struct xen_drm_front_info
*front_info
= drm_info
->front_info
;
458 xen_drm_front_kms_fini(drm_info
);
460 drm_atomic_helper_shutdown(dev
);
461 drm_mode_config_cleanup(dev
);
466 if (front_info
->cfg
.be_alloc
)
467 xenbus_switch_state(front_info
->xb_dev
,
468 XenbusStateInitialising
);
473 static const struct file_operations xen_drm_dev_fops
= {
474 .owner
= THIS_MODULE
,
476 .release
= drm_release
,
477 .unlocked_ioctl
= drm_ioctl
,
479 .compat_ioctl
= drm_compat_ioctl
,
484 .mmap
= xen_drm_front_gem_mmap
,
487 static const struct vm_operations_struct xen_drm_drv_vm_ops
= {
488 .open
= drm_gem_vm_open
,
489 .close
= drm_gem_vm_close
,
492 static struct drm_driver xen_drm_driver
= {
493 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
| DRIVER_ATOMIC
,
494 .release
= xen_drm_drv_release
,
495 .gem_vm_ops
= &xen_drm_drv_vm_ops
,
496 .gem_free_object_unlocked
= xen_drm_drv_free_object_unlocked
,
497 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
498 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
499 .gem_prime_import_sg_table
= xen_drm_front_gem_import_sg_table
,
500 .gem_prime_get_sg_table
= xen_drm_front_gem_get_sg_table
,
501 .gem_prime_vmap
= xen_drm_front_gem_prime_vmap
,
502 .gem_prime_vunmap
= xen_drm_front_gem_prime_vunmap
,
503 .gem_prime_mmap
= xen_drm_front_gem_prime_mmap
,
504 .dumb_create
= xen_drm_drv_dumb_create
,
505 .fops
= &xen_drm_dev_fops
,
507 .desc
= "Xen PV DRM Display Unit",
514 static int xen_drm_drv_init(struct xen_drm_front_info
*front_info
)
516 struct device
*dev
= &front_info
->xb_dev
->dev
;
517 struct xen_drm_front_drm_info
*drm_info
;
518 struct drm_device
*drm_dev
;
521 DRM_INFO("Creating %s\n", xen_drm_driver
.desc
);
523 drm_info
= kzalloc(sizeof(*drm_info
), GFP_KERNEL
);
529 drm_info
->front_info
= front_info
;
530 front_info
->drm_info
= drm_info
;
532 drm_dev
= drm_dev_alloc(&xen_drm_driver
, dev
);
533 if (IS_ERR(drm_dev
)) {
534 ret
= PTR_ERR(drm_dev
);
538 drm_info
->drm_dev
= drm_dev
;
540 drm_dev
->dev_private
= drm_info
;
542 ret
= xen_drm_front_kms_init(drm_info
);
544 DRM_ERROR("Failed to initialize DRM/KMS, ret %d\n", ret
);
548 ret
= drm_dev_register(drm_dev
, 0);
552 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
553 xen_drm_driver
.name
, xen_drm_driver
.major
,
554 xen_drm_driver
.minor
, xen_drm_driver
.patchlevel
,
555 xen_drm_driver
.date
, drm_dev
->primary
->index
);
560 drm_dev_unregister(drm_dev
);
562 drm_kms_helper_poll_fini(drm_dev
);
563 drm_mode_config_cleanup(drm_dev
);
569 static void xen_drm_drv_fini(struct xen_drm_front_info
*front_info
)
571 struct xen_drm_front_drm_info
*drm_info
= front_info
->drm_info
;
572 struct drm_device
*dev
;
577 dev
= drm_info
->drm_dev
;
581 /* Nothing to do if device is already unplugged */
582 if (drm_dev_is_unplugged(dev
))
585 drm_kms_helper_poll_fini(dev
);
589 front_info
->drm_info
= NULL
;
591 xen_drm_front_evtchnl_free_all(front_info
);
592 dbuf_free_all(&front_info
->dbuf_list
);
595 * If we are not using backend allocated buffers, then tell the
596 * backend we are ready to (re)initialize. Otherwise, wait for
597 * drm_driver.release.
599 if (!front_info
->cfg
.be_alloc
)
600 xenbus_switch_state(front_info
->xb_dev
,
601 XenbusStateInitialising
);
604 static int displback_initwait(struct xen_drm_front_info
*front_info
)
606 struct xen_drm_front_cfg
*cfg
= &front_info
->cfg
;
609 cfg
->front_info
= front_info
;
610 ret
= xen_drm_front_cfg_card(front_info
, cfg
);
614 DRM_INFO("Have %d connector(s)\n", cfg
->num_connectors
);
615 /* Create event channels for all connectors and publish */
616 ret
= xen_drm_front_evtchnl_create_all(front_info
);
620 return xen_drm_front_evtchnl_publish_all(front_info
);
623 static int displback_connect(struct xen_drm_front_info
*front_info
)
625 xen_drm_front_evtchnl_set_state(front_info
, EVTCHNL_STATE_CONNECTED
);
626 return xen_drm_drv_init(front_info
);
629 static void displback_disconnect(struct xen_drm_front_info
*front_info
)
631 if (!front_info
->drm_info
)
634 /* Tell the backend to wait until we release the DRM driver. */
635 xenbus_switch_state(front_info
->xb_dev
, XenbusStateReconfiguring
);
637 xen_drm_drv_fini(front_info
);
640 static void displback_changed(struct xenbus_device
*xb_dev
,
641 enum xenbus_state backend_state
)
643 struct xen_drm_front_info
*front_info
= dev_get_drvdata(&xb_dev
->dev
);
646 DRM_DEBUG("Backend state is %s, front is %s\n",
647 xenbus_strstate(backend_state
),
648 xenbus_strstate(xb_dev
->state
));
650 switch (backend_state
) {
651 case XenbusStateReconfiguring
:
653 case XenbusStateReconfigured
:
655 case XenbusStateInitialised
:
658 case XenbusStateInitialising
:
659 if (xb_dev
->state
== XenbusStateReconfiguring
)
662 /* recovering after backend unexpected closure */
663 displback_disconnect(front_info
);
666 case XenbusStateInitWait
:
667 if (xb_dev
->state
== XenbusStateReconfiguring
)
670 /* recovering after backend unexpected closure */
671 displback_disconnect(front_info
);
672 if (xb_dev
->state
!= XenbusStateInitialising
)
675 ret
= displback_initwait(front_info
);
677 xenbus_dev_fatal(xb_dev
, ret
, "initializing frontend");
679 xenbus_switch_state(xb_dev
, XenbusStateInitialised
);
682 case XenbusStateConnected
:
683 if (xb_dev
->state
!= XenbusStateInitialised
)
686 ret
= displback_connect(front_info
);
688 displback_disconnect(front_info
);
689 xenbus_dev_fatal(xb_dev
, ret
, "connecting backend");
691 xenbus_switch_state(xb_dev
, XenbusStateConnected
);
695 case XenbusStateClosing
:
697 * in this state backend starts freeing resources,
698 * so let it go into closed state, so we can also
703 case XenbusStateUnknown
:
705 case XenbusStateClosed
:
706 if (xb_dev
->state
== XenbusStateClosed
)
709 displback_disconnect(front_info
);
714 static int xen_drv_probe(struct xenbus_device
*xb_dev
,
715 const struct xenbus_device_id
*id
)
717 struct xen_drm_front_info
*front_info
;
718 struct device
*dev
= &xb_dev
->dev
;
721 ret
= dma_coerce_mask_and_coherent(dev
, DMA_BIT_MASK(64));
723 DRM_ERROR("Cannot setup DMA mask, ret %d", ret
);
727 front_info
= devm_kzalloc(&xb_dev
->dev
,
728 sizeof(*front_info
), GFP_KERNEL
);
732 front_info
->xb_dev
= xb_dev
;
733 spin_lock_init(&front_info
->io_lock
);
734 INIT_LIST_HEAD(&front_info
->dbuf_list
);
735 dev_set_drvdata(&xb_dev
->dev
, front_info
);
737 return xenbus_switch_state(xb_dev
, XenbusStateInitialising
);
740 static int xen_drv_remove(struct xenbus_device
*dev
)
742 struct xen_drm_front_info
*front_info
= dev_get_drvdata(&dev
->dev
);
745 xenbus_switch_state(dev
, XenbusStateClosing
);
748 * On driver removal it is disconnected from XenBus,
749 * so no backend state change events come via .otherend_changed
750 * callback. This prevents us from exiting gracefully, e.g.
751 * signaling the backend to free event channels, waiting for its
752 * state to change to XenbusStateClosed and cleaning at our end.
753 * Normally when front driver removed backend will finally go into
754 * XenbusStateInitWait state.
756 * Workaround: read backend's state manually and wait with time-out.
758 while ((xenbus_read_unsigned(front_info
->xb_dev
->otherend
, "state",
759 XenbusStateUnknown
) != XenbusStateInitWait
) &&
766 state
= xenbus_read_unsigned(front_info
->xb_dev
->otherend
,
767 "state", XenbusStateUnknown
);
768 DRM_ERROR("Backend state is %s while removing driver\n",
769 xenbus_strstate(state
));
772 xen_drm_drv_fini(front_info
);
773 xenbus_frontend_closed(dev
);
777 static const struct xenbus_device_id xen_driver_ids
[] = {
778 { XENDISPL_DRIVER_NAME
},
782 static struct xenbus_driver xen_driver
= {
783 .ids
= xen_driver_ids
,
784 .probe
= xen_drv_probe
,
785 .remove
= xen_drv_remove
,
786 .otherend_changed
= displback_changed
,
789 static int __init
xen_drv_init(void)
791 /* At the moment we only support case with XEN_PAGE_SIZE == PAGE_SIZE */
792 if (XEN_PAGE_SIZE
!= PAGE_SIZE
) {
793 DRM_ERROR(XENDISPL_DRIVER_NAME
": different kernel and Xen page sizes are not supported: XEN_PAGE_SIZE (%lu) != PAGE_SIZE (%lu)\n",
794 XEN_PAGE_SIZE
, PAGE_SIZE
);
801 if (!xen_has_pv_devices())
804 DRM_INFO("Registering XEN PV " XENDISPL_DRIVER_NAME
"\n");
805 return xenbus_register_frontend(&xen_driver
);
808 static void __exit
xen_drv_fini(void)
810 DRM_INFO("Unregistering XEN PV " XENDISPL_DRIVER_NAME
"\n");
811 xenbus_unregister_driver(&xen_driver
);
814 module_init(xen_drv_init
);
815 module_exit(xen_drv_fini
);
817 MODULE_DESCRIPTION("Xen para-virtualized display device frontend");
818 MODULE_LICENSE("GPL");
819 MODULE_ALIAS("xen:" XENDISPL_DRIVER_NAME
);