nv50_screen.h revision be68782d9aebf6f6575bb8cc9cfc66b7bad79644
1#ifndef __NV50_SCREEN_H__
2#define __NV50_SCREEN_H__
3
4#define NOUVEAU_NVC0
5#include "nouveau/nouveau_screen.h"
6#include "nouveau/nouveau_fence.h"
7#include "nouveau/nouveau_mm.h"
8#undef NOUVEAU_NVC0
9#include "nv50_winsys.h"
10#include "nv50_stateobj.h"
11
12#define NV50_TIC_MAX_ENTRIES 2048
13#define NV50_TSC_MAX_ENTRIES 2048
14
15struct nv50_context;
16
17#define NV50_SCRATCH_SIZE (2 << 20)
18#define NV50_SCRATCH_NR_BUFFERS 2
19
20struct nv50_screen {
21   struct nouveau_screen base;
22   struct nouveau_winsys *nvws;
23
24   struct nv50_context *cur_ctx;
25
26   struct nouveau_bo *code;
27   struct nouveau_bo *uniforms;
28   struct nouveau_bo *txc; /* TIC (offset 0) and TSC (65536) */
29   struct nouveau_bo *stack_bo;
30   struct nouveau_bo *tls_bo;
31
32   uint64_t tls_size;
33
34   struct nouveau_resource *vp_code_heap;
35   struct nouveau_resource *gp_code_heap;
36   struct nouveau_resource *fp_code_heap;
37
38   struct {
39      void **entries;
40      int next;
41      uint32_t lock[NV50_TIC_MAX_ENTRIES / 32];
42   } tic;
43
44   struct {
45      void **entries;
46      int next;
47      uint32_t lock[NV50_TSC_MAX_ENTRIES / 32];
48   } tsc;
49
50   struct {
51      uint32_t *map;
52      struct nouveau_bo *bo;
53   } fence;
54
55   struct nouveau_notifier *sync;
56
57   struct nouveau_mman *mm_VRAM_fe0;
58
59   struct nouveau_grobj *tesla;
60   struct nouveau_grobj *eng2d;
61   struct nouveau_grobj *m2mf;
62};
63
64static INLINE struct nv50_screen *
65nv50_screen(struct pipe_screen *screen)
66{
67   return (struct nv50_screen *)screen;
68}
69
70void nv50_screen_make_buffers_resident(struct nv50_screen *);
71
72int nv50_screen_tic_alloc(struct nv50_screen *, void *);
73int nv50_screen_tsc_alloc(struct nv50_screen *, void *);
74
75static INLINE void
76nv50_resource_fence(struct nv04_resource *res, uint32_t flags)
77{
78   struct nv50_screen *screen = nv50_screen(res->base.screen);
79
80   if (res->mm) {
81      nouveau_fence_ref(screen->base.fence.current, &res->fence);
82
83      if (flags & NOUVEAU_BO_WR)
84         nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
85   }
86}
87
88static INLINE void
89nv50_resource_validate(struct nv04_resource *res, uint32_t flags)
90{
91   struct nv50_screen *screen = nv50_screen(res->base.screen);
92
93   if (likely(res->bo)) {
94      nouveau_bo_validate(screen->base.channel, res->bo, flags);
95
96      if (flags & NOUVEAU_BO_WR)
97         res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
98      if (flags & NOUVEAU_BO_RD)
99         res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
100
101      nv50_resource_fence(res, flags);
102   }
103}
104
105struct nv50_format {
106   uint32_t rt;
107   uint32_t tic;
108   uint32_t vtx;
109   uint32_t usage;
110};
111
112extern const struct nv50_format nv50_format_table[];
113
114static INLINE void
115nv50_screen_tic_unlock(struct nv50_screen *screen, struct nv50_tic_entry *tic)
116{
117   if (tic->id >= 0)
118      screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
119}
120
121static INLINE void
122nv50_screen_tsc_unlock(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
123{
124   if (tsc->id >= 0)
125      screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
126}
127
128static INLINE void
129nv50_screen_tic_free(struct nv50_screen *screen, struct nv50_tic_entry *tic)
130{
131   if (tic->id >= 0) {
132      screen->tic.entries[tic->id] = NULL;
133      screen->tic.lock[tic->id / 32] &= ~(1 << (tic->id % 32));
134   }
135}
136
137static INLINE void
138nv50_screen_tsc_free(struct nv50_screen *screen, struct nv50_tsc_entry *tsc)
139{
140   if (tsc->id >= 0) {
141      screen->tsc.entries[tsc->id] = NULL;
142      screen->tsc.lock[tsc->id / 32] &= ~(1 << (tsc->id % 32));
143   }
144}
145
146#endif
147