Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 1 | #ifndef __NOUVEAU_LIBDRM_PRIVATE_H__ |
| 2 | #define __NOUVEAU_LIBDRM_PRIVATE_H__ |
| 3 | |
| 4 | #include <xf86drm.h> |
| 5 | #include <xf86atomic.h> |
| 6 | #include "nouveau_drm.h" |
| 7 | |
| 8 | #include "nouveau.h" |
| 9 | |
| 10 | #ifdef DEBUG |
| 11 | uint32_t nouveau_debug; |
| 12 | #define dbg_on(lvl) (nouveau_debug & (1 << lvl)) |
| 13 | #define dbg(lvl, fmt, args...) do { \ |
| 14 | if (dbg_on((lvl))) \ |
| 15 | fprintf(stderr, "nouveau: "fmt, ##args); \ |
| 16 | } while(0) |
| 17 | #else |
| 18 | #define dbg_on(lvl) (0) |
| 19 | #define dbg(lvl, fmt, args...) |
| 20 | #endif |
| 21 | #define err(fmt, args...) fprintf(stderr, "nouveau: "fmt, ##args) |
| 22 | |
| 23 | struct nouveau_client_kref { |
| 24 | struct drm_nouveau_gem_pushbuf_bo *kref; |
| 25 | struct nouveau_pushbuf *push; |
| 26 | }; |
| 27 | |
| 28 | struct nouveau_client_priv { |
| 29 | struct nouveau_client base; |
| 30 | struct nouveau_client_kref *kref; |
| 31 | unsigned kref_nr; |
| 32 | }; |
| 33 | |
| 34 | static inline struct nouveau_client_priv * |
| 35 | nouveau_client(struct nouveau_client *client) |
| 36 | { |
| 37 | return (struct nouveau_client_priv *)client; |
| 38 | } |
| 39 | |
| 40 | static inline struct drm_nouveau_gem_pushbuf_bo * |
| 41 | cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo) |
| 42 | { |
| 43 | struct nouveau_client_priv *pcli = nouveau_client(client); |
| 44 | struct drm_nouveau_gem_pushbuf_bo *kref = NULL; |
| 45 | if (pcli->kref_nr > bo->handle) |
| 46 | kref = pcli->kref[bo->handle].kref; |
| 47 | return kref; |
| 48 | } |
| 49 | |
| 50 | static inline struct nouveau_pushbuf * |
| 51 | cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo) |
| 52 | { |
| 53 | struct nouveau_client_priv *pcli = nouveau_client(client); |
| 54 | struct nouveau_pushbuf *push = NULL; |
| 55 | if (pcli->kref_nr > bo->handle) |
| 56 | push = pcli->kref[bo->handle].push; |
| 57 | return push; |
| 58 | } |
| 59 | |
| 60 | static inline void |
| 61 | cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo, |
| 62 | struct drm_nouveau_gem_pushbuf_bo *kref, |
| 63 | struct nouveau_pushbuf *push) |
| 64 | { |
| 65 | struct nouveau_client_priv *pcli = nouveau_client(client); |
| 66 | if (pcli->kref_nr <= bo->handle) { |
| 67 | pcli->kref = realloc(pcli->kref, |
| 68 | sizeof(*pcli->kref) * bo->handle * 2); |
| 69 | while (pcli->kref_nr < bo->handle * 2) { |
| 70 | pcli->kref[pcli->kref_nr].kref = NULL; |
| 71 | pcli->kref[pcli->kref_nr].push = NULL; |
| 72 | pcli->kref_nr++; |
| 73 | } |
| 74 | } |
| 75 | pcli->kref[bo->handle].kref = kref; |
| 76 | pcli->kref[bo->handle].push = push; |
| 77 | } |
| 78 | |
| 79 | struct nouveau_bo_priv { |
| 80 | struct nouveau_bo base; |
| 81 | struct nouveau_list head; |
| 82 | atomic_t refcnt; |
| 83 | uint64_t map_handle; |
| 84 | uint32_t name; |
| 85 | uint32_t access; |
| 86 | }; |
| 87 | |
| 88 | static inline struct nouveau_bo_priv * |
| 89 | nouveau_bo(struct nouveau_bo *bo) |
| 90 | { |
| 91 | return (struct nouveau_bo_priv *)bo; |
| 92 | } |
| 93 | |
| 94 | struct nouveau_device_priv { |
| 95 | struct nouveau_device base; |
| 96 | int close; |
| 97 | atomic_t lock; |
| 98 | struct nouveau_list bo_list; |
| 99 | uint32_t *client; |
| 100 | int nr_client; |
| 101 | bool have_bo_usage; |
Marcin Slusarz | f92d796 | 2013-03-03 22:34:38 +0100 | [diff] [blame] | 102 | int gart_limit_percent, vram_limit_percent; |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static inline struct nouveau_device_priv * |
| 106 | nouveau_device(struct nouveau_device *dev) |
| 107 | { |
| 108 | return (struct nouveau_device_priv *)dev; |
| 109 | } |
| 110 | |
| 111 | int |
| 112 | nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t); |
| 113 | |
| 114 | /* abi16.c */ |
| 115 | int abi16_chan_nv04(struct nouveau_object *); |
| 116 | int abi16_chan_nvc0(struct nouveau_object *); |
Ben Skeggs | c41b494 | 2012-11-23 12:40:30 +1000 | [diff] [blame] | 117 | int abi16_chan_nve0(struct nouveau_object *); |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 118 | int abi16_engobj(struct nouveau_object *); |
| 119 | int abi16_ntfy(struct nouveau_object *); |
| 120 | void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *); |
| 121 | int abi16_bo_init(struct nouveau_bo *, uint32_t alignment, |
| 122 | union nouveau_bo_config *); |
| 123 | |
| 124 | #endif |