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