1 /*
2 * Copyright © 2011 Texas Instruments, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Soft-
6 * ware"), to deal in the Software without restriction, including without
7 * limitation the rights to use, copy, modify, merge, publish, distribute,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, provided that the above copyright
10 * notice(s) and this permission notice appear in all copies of the Soft-
11 * ware and that both the above copyright notice(s) and this permission
12 * notice appear in supporting documentation.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
17 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
18 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
19 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
22 * MANCE OF THIS SOFTWARE.
23 *
24 * Except as contained in this notice, the name of a copyright holder shall
25 * not be used in advertising or otherwise to promote the sale, use or
26 * other dealings in this Software without prior written authorization of
27 * the copyright holder.
28 *
29 * Authors:
30 * Rob Clark (rob@ti.com)
31 */
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
37 #include "dri2util.h"
39 #include <nouveau_bo.h>
40 #include <nouveau_drmif.h>
42 struct nouveau_device *dev;
44 static void setup(int fd)
45 {
46 int ret = nouveau_device_open_existing(&dev, 0, fd, 0);
47 if (ret) {
48 ERROR_MSG("nouveau_device_open_existing failed: %d", ret);
49 }
50 }
52 static void * init(DRI2Buffer *dri2buf)
53 {
54 struct nouveau_bo *bo = NULL;
55 int ret = nouveau_bo_handle_ref(dev, dri2buf->name, &bo);
56 if (ret) {
57 ERROR_MSG("nouveau_bo_handle_ref failed: %d", ret);
58 return NULL;
59 }
60 return bo;
61 }
63 static char * prep(void *hdl)
64 {
65 struct nouveau_bo *bo = hdl;
66 int ret = nouveau_bo_map(bo, NOUVEAU_BO_RDWR);
67 if (ret) {
68 ERROR_MSG("nouveau_bo_map failed: %d", ret);
69 return NULL;
70 }
71 return bo->map;
72 }
74 static void fini(void *hdl)
75 {
76 struct nouveau_bo *bo = hdl;
77 nouveau_bo_unmap(bo);
78 }
80 Backend nouveau_backend = {
81 .setup = setup,
82 .init = init,
83 .prep = prep,
84 .fini = fini,
85 };