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