2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
32 #include "libdrm_lists.h"
37 struct nouveau_bufref_priv
{
38 struct nouveau_bufref base
;
39 struct nouveau_bufref_priv
*next
;
40 struct nouveau_bufctx
*bufctx
;
43 struct nouveau_bufbin_priv
{
44 struct nouveau_bufref_priv
*list
;
48 struct nouveau_bufctx_priv
{
49 struct nouveau_bufctx base
;
50 struct nouveau_bufref_priv
*free
;
52 struct nouveau_bufbin_priv bins
[];
55 static inline struct nouveau_bufctx_priv
*
56 nouveau_bufctx(struct nouveau_bufctx
*bctx
)
58 return (struct nouveau_bufctx_priv
*)bctx
;
62 nouveau_bufctx_new(struct nouveau_client
*client
, int bins
,
63 struct nouveau_bufctx
**pbctx
)
65 struct nouveau_bufctx_priv
*priv
;
67 priv
= calloc(1, sizeof(*priv
) + sizeof(priv
->bins
[0]) * bins
);
69 DRMINITLISTHEAD(&priv
->base
.head
);
70 DRMINITLISTHEAD(&priv
->base
.pending
);
71 DRMINITLISTHEAD(&priv
->base
.current
);
72 priv
->base
.client
= client
;
82 nouveau_bufctx_del(struct nouveau_bufctx
**pbctx
)
84 struct nouveau_bufctx_priv
*pctx
= nouveau_bufctx(*pbctx
);
85 struct nouveau_bufref_priv
*pref
;
87 while (pctx
->nr_bins
--)
88 nouveau_bufctx_reset(&pctx
->base
, pctx
->nr_bins
);
89 while ((pref
= pctx
->free
)) {
90 pctx
->free
= pref
->next
;
99 nouveau_bufctx_reset(struct nouveau_bufctx
*bctx
, int bin
)
101 struct nouveau_bufctx_priv
*pctx
= nouveau_bufctx(bctx
);
102 struct nouveau_bufbin_priv
*pbin
= &pctx
->bins
[bin
];
103 struct nouveau_bufref_priv
*pref
;
105 while ((pref
= pbin
->list
)) {
106 DRMLISTDELINIT(&pref
->base
.thead
);
107 pbin
->list
= pref
->next
;
108 pref
->next
= pctx
->free
;
112 bctx
->relocs
-= pbin
->relocs
;
116 drm_public
struct nouveau_bufref
*
117 nouveau_bufctx_refn(struct nouveau_bufctx
*bctx
, int bin
,
118 struct nouveau_bo
*bo
, uint32_t flags
)
120 struct nouveau_bufctx_priv
*pctx
= nouveau_bufctx(bctx
);
121 struct nouveau_bufbin_priv
*pbin
= &pctx
->bins
[bin
];
122 struct nouveau_bufref_priv
*pref
= pctx
->free
;
125 pref
= malloc(sizeof(*pref
));
127 pctx
->free
= pref
->next
;
131 pref
->base
.flags
= flags
;
132 pref
->base
.packet
= 0;
134 DRMLISTADDTAIL(&pref
->base
.thead
, &bctx
->pending
);
136 pref
->next
= pbin
->list
;
143 drm_public
struct nouveau_bufref
*
144 nouveau_bufctx_mthd(struct nouveau_bufctx
*bctx
, int bin
, uint32_t packet
,
145 struct nouveau_bo
*bo
, uint64_t data
, uint32_t flags
,
146 uint32_t vor
, uint32_t tor
)
148 struct nouveau_bufctx_priv
*pctx
= nouveau_bufctx(bctx
);
149 struct nouveau_bufbin_priv
*pbin
= &pctx
->bins
[bin
];
150 struct nouveau_bufref
*bref
= nouveau_bufctx_refn(bctx
, bin
, bo
, flags
);
152 bref
->packet
= packet
;