1#ifndef __NOUVEAU_BUFFER_H__
2#define __NOUVEAU_BUFFER_H__
3
4#include "util/u_transfer.h"
5#include "util/u_double_list.h"
6
7struct pipe_resource;
8struct nouveau_context;
9struct nouveau_bo;
10
11/* DIRTY: buffer was (or will be after the next flush) written to by GPU and
12 *  resource->data has not been updated to reflect modified VRAM contents
13 *
14 * USER_MEMORY: resource->data is a pointer to client memory and may change
15 *  between GL calls
16 */
17#define NOUVEAU_BUFFER_STATUS_GPU_READING (1 << 0)
18#define NOUVEAU_BUFFER_STATUS_GPU_WRITING (1 << 1)
19#define NOUVEAU_BUFFER_STATUS_USER_MEMORY (1 << 7)
20
21/* Resources, if mapped into the GPU's address space, are guaranteed to
22 * have constant virtual addresses (nv50+).
23 *
24 * The address of a resource will lie within the nouveau_bo referenced,
25 * and this bo should be added to the memory manager's validation list.
26 */
27struct nv04_resource {
28   struct pipe_resource base;
29   const struct u_resource_vtbl *vtbl;
30
31   uint64_t address; /* virtual address (nv50+) */
32
33   uint8_t *data;
34   struct nouveau_bo *bo;
35   uint32_t offset;
36
37   uint8_t status;
38   uint8_t domain;
39
40   struct nouveau_fence *fence;
41   struct nouveau_fence *fence_wr;
42
43   struct nouveau_mm_allocation *mm;
44};
45
46void
47nouveau_buffer_release_gpu_storage(struct nv04_resource *);
48
49boolean
50nouveau_buffer_download(struct nouveau_context *, struct nv04_resource *,
51                        unsigned start, unsigned size);
52
53boolean
54nouveau_buffer_migrate(struct nouveau_context *,
55                       struct nv04_resource *, unsigned domain);
56
57void *
58nouveau_resource_map_offset(struct nouveau_context *, struct nv04_resource *,
59                            uint32_t offset, uint32_t flags);
60
61static INLINE void
62nouveau_resource_unmap(struct nv04_resource *res)
63{
64   /* no-op */
65}
66
67static INLINE struct nv04_resource *
68nv04_resource(struct pipe_resource *resource)
69{
70   return (struct nv04_resource *)resource;
71}
72
73/* is resource mapped into the GPU's address space (i.e. VRAM or GART) ? */
74static INLINE boolean
75nouveau_resource_mapped_by_gpu(struct pipe_resource *resource)
76{
77   return nv04_resource(resource)->domain != 0;
78}
79
80struct pipe_resource *
81nouveau_buffer_create(struct pipe_screen *pscreen,
82                      const struct pipe_resource *templ);
83
84struct pipe_resource *
85nouveau_user_buffer_create(struct pipe_screen *screen, void *ptr,
86                           unsigned bytes, unsigned usage);
87
88boolean
89nouveau_user_buffer_upload(struct nouveau_context *, struct nv04_resource *,
90                           unsigned base, unsigned size);
91
92/* Copy data to a scratch buffer and return address & bo the data resides in.
93 * Returns 0 on failure.
94 */
95uint64_t
96nouveau_scratch_data(struct nouveau_context *,
97                     const void *data, unsigned base, unsigned size,
98                     struct nouveau_bo **);
99
100#endif
101