Source
x
usif_notify_new(struct drm_file *f, void *data, u32 size, void *argv, u32 argc)
/*
* Copyright 2014 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Authors: Ben Skeggs <bskeggs@redhat.com>
*/
struct usif_notify_p {
struct drm_pending_event base;
struct {
struct drm_event base;
u8 data[];
} e;
};
struct usif_notify {
struct list_head head;
atomic_t enabled;
u32 handle;
u16 reply;
u8 route;
u64 token;
struct usif_notify_p *p;
};
static inline struct usif_notify *
usif_notify_find(struct drm_file *filp, u32 handle)
{
struct nouveau_cli *cli = nouveau_cli(filp);
struct usif_notify *ntfy;
list_for_each_entry(ntfy, &cli->notifys, head) {
if (ntfy->handle == handle)
return ntfy;
}
return NULL;
}
static inline void
usif_notify_dtor(struct usif_notify *ntfy)
{
list_del(&ntfy->head);
kfree(ntfy);
}
int
usif_notify(const void *header, u32 length, const void *data, u32 size)
{
struct usif_notify *ntfy = NULL;
const union {
struct nvif_notify_rep_v0 v0;
} *rep = header;
struct drm_device *dev;
struct drm_file *filp;
unsigned long flags;
if (length == sizeof(rep->v0) && rep->v0.version == 0) {
if (WARN_ON(!(ntfy = (void *)(unsigned long)rep->v0.token)))
return NVIF_NOTIFY_DROP;
BUG_ON(rep->v0.route != NVDRM_NOTIFY_USIF);
} else
if (WARN_ON(1))
return NVIF_NOTIFY_DROP;
if (WARN_ON(!ntfy->p || ntfy->reply != (length + size)))
return NVIF_NOTIFY_DROP;