blob: 46192074328a96036f4e245fba435b38ed357ec4 [file] [log] [blame]
Jerome Glissefd266ec2010-09-17 10:41:50 -04001/*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26#ifndef R600_PRIV_H
27#define R600_PRIV_H
28
29#include <errno.h>
30#include <stdint.h>
31#include <stdlib.h>
32#include <assert.h>
Jerome Glisse1235bec2010-09-29 15:05:19 -040033#include <pipebuffer/pb_bufmgr.h>
Dave Airlie3c38e4f2010-10-05 15:35:52 +100034#include "util/u_double_list.h"
Jerome Glissefd266ec2010-09-17 10:41:50 -040035#include "r600.h"
36
Jerome Glissefd266ec2010-09-17 10:41:50 -040037struct radeon {
38 int fd;
39 int refcount;
40 unsigned device;
41 unsigned family;
Jerome Glisse363dfb82010-09-20 11:58:00 -040042 enum chip_class chip_class;
Dave Airlie301ab492010-09-29 09:17:59 +100043 struct pb_manager *kman; /* kernel bo manager */
44 struct pb_manager *cman; /* cached bo manager */
Jerome Glissefd266ec2010-09-17 10:41:50 -040045};
46
47struct radeon *r600_new(int fd, unsigned device);
48void r600_delete(struct radeon *r600);
49
50struct r600_reg {
Jerome Glisse56469642010-09-28 17:37:56 -040051 unsigned opcode;
52 unsigned offset_base;
53 unsigned offset;
Jerome Glisseca352922010-09-21 20:24:51 -040054 unsigned need_bo;
55 unsigned flush_flags;
Jerome Glissefd266ec2010-09-17 10:41:50 -040056};
57
Jerome Glisse1235bec2010-09-29 15:05:19 -040058struct radeon_bo {
59 struct pipe_reference reference;
60 unsigned handle;
61 unsigned size;
62 unsigned alignment;
63 unsigned map_count;
64 void *data;
Dave Airlie3c38e4f2010-10-05 15:35:52 +100065 struct list_head fencedlist;
66 boolean shared;
Dave Airlie05813ad2010-10-05 15:51:38 +100067 int64_t last_busy;
68 boolean set_busy;
Jerome Glisse12d16e52010-10-05 08:42:42 -040069 struct r600_reloc *reloc;
70 unsigned reloc_id;
Jerome Glisse1235bec2010-09-29 15:05:19 -040071};
72
Jerome Glisse294c9fc2010-10-04 10:06:13 -040073struct r600_bo {
Jerome Glisse1235bec2010-09-29 15:05:19 -040074 struct pipe_reference reference;
75 struct pb_buffer *pb;
Jerome Glisse674452f2010-10-04 10:37:32 -040076 unsigned size;
Jerome Glisse1235bec2010-09-29 15:05:19 -040077};
78
79
Jerome Glissefd266ec2010-09-17 10:41:50 -040080/* radeon_pciid.c */
81unsigned radeon_family_from_device(unsigned device);
82
Jerome Glisse1235bec2010-09-29 15:05:19 -040083/* r600_drm.c */
84struct radeon *radeon_decref(struct radeon *radeon);
85
86/* radeon_bo.c */
Jerome Glisse1235bec2010-09-29 15:05:19 -040087struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
88 unsigned size, unsigned alignment, void *ptr);
Jerome Glisse1235bec2010-09-29 15:05:19 -040089void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst,
90 struct radeon_bo *src);
91int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
92int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain);
Dave Airliedbcd6522010-09-30 09:07:07 +100093void radeon_bo_pbmgr_flush_maps(struct pb_manager *_mgr);
Dave Airlie3c38e4f2010-10-05 15:35:52 +100094int radeon_bo_fencelist(struct radeon *radeon, struct radeon_bo **bolist, uint32_t num_bo);
95
Jerome Glisse1235bec2010-09-29 15:05:19 -040096
97/* radeon_bo_pb.c */
Jerome Glisse674452f2010-10-04 10:37:32 -040098struct radeon_bo *radeon_bo_pb_get_bo(struct pb_buffer *_buf);
Dave Airliedbcd6522010-09-30 09:07:07 +100099struct pb_manager *radeon_bo_pbmgr_create(struct radeon *radeon);
Jerome Glisse1235bec2010-09-29 15:05:19 -0400100struct pb_buffer *radeon_bo_pb_create_buffer_from_handle(struct pb_manager *_mgr,
101 uint32_t handle);
102
Jerome Glisse674452f2010-10-04 10:37:32 -0400103/* r600_hw_context.c */
104void r600_context_bo_reloc(struct r600_context *ctx, u32 *pm4, struct r600_bo *rbo);
105struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset);
106int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, unsigned nreg);
107
Jerome Glisse294c9fc2010-10-04 10:06:13 -0400108/* r600_bo.c */
109unsigned r600_bo_get_handle(struct r600_bo *bo);
110unsigned r600_bo_get_size(struct r600_bo *bo);
Jerome Glisse674452f2010-10-04 10:37:32 -0400111static INLINE struct radeon_bo *r600_bo_get_bo(struct r600_bo *bo)
112{
113 return radeon_bo_pb_get_bo(bo->pb);
114}
Jerome Glisse1235bec2010-09-29 15:05:19 -0400115
Jerome Glisse56469642010-09-28 17:37:56 -0400116#define CTX_RANGE_ID(ctx, offset) (((offset) >> (ctx)->hash_shift) & 255)
117#define CTX_BLOCK_ID(ctx, offset) ((offset) & ((1 << (ctx)->hash_shift) - 1))
Jerome Glissea8526152010-09-26 12:06:46 -0400118
Jerome Glisse56469642010-09-28 17:37:56 -0400119static void inline r600_context_reg(struct r600_context *ctx,
Jerome Glissea8526152010-09-26 12:06:46 -0400120 unsigned offset, unsigned value,
121 unsigned mask)
122{
Jerome Glisse56469642010-09-28 17:37:56 -0400123 struct r600_range *range;
124 struct r600_block *block;
Jerome Glissea8526152010-09-26 12:06:46 -0400125 unsigned id;
126
Jerome Glisse56469642010-09-28 17:37:56 -0400127 range = &ctx->range[CTX_RANGE_ID(ctx, offset)];
128 block = range->blocks[CTX_BLOCK_ID(ctx, offset)];
Jerome Glissea8526152010-09-26 12:06:46 -0400129 id = (offset - block->start_offset) >> 2;
Jerome Glisse02826822010-09-27 17:00:07 -0400130 block->reg[id] &= ~mask;
131 block->reg[id] |= value;
Jerome Glissea8526152010-09-26 12:06:46 -0400132 if (!(block->status & R600_BLOCK_STATUS_DIRTY)) {
Jerome Glisse02826822010-09-27 17:00:07 -0400133 ctx->pm4_dirty_cdwords += block->pm4_ndwords;
John Doedde13912010-09-30 17:30:25 -0400134 block->status |= R600_BLOCK_STATUS_ENABLED;
135 block->status |= R600_BLOCK_STATUS_DIRTY;
Jerome Glissea8526152010-09-26 12:06:46 -0400136 }
Jerome Glissea8526152010-09-26 12:06:46 -0400137}
138
Jerome Glisse56469642010-09-28 17:37:56 -0400139static inline void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block)
140{
Jerome Glisse56469642010-09-28 17:37:56 -0400141 int id;
142
143 for (int j = 0; j < block->nreg; j++) {
144 if (block->pm4_bo_index[j]) {
145 /* find relocation */
146 id = block->pm4_bo_index[j];
Jerome Glisse56469642010-09-28 17:37:56 -0400147 for (int k = 0; k < block->reloc[id].nreloc; k++) {
148 r600_context_bo_reloc(ctx,
149 &block->pm4[block->reloc[id].bo_pm4_index[k]],
Jerome Glisse674452f2010-10-04 10:37:32 -0400150 block->reloc[id].bo);
Jerome Glisse56469642010-09-28 17:37:56 -0400151 }
152 }
153 }
154 memcpy(&ctx->pm4[ctx->pm4_cdwords], block->pm4, block->pm4_ndwords * 4);
155 ctx->pm4_cdwords += block->pm4_ndwords;
156 block->status ^= R600_BLOCK_STATUS_DIRTY;
157}
158
John Doe40181ae2010-09-30 17:53:36 -0400159static inline int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo)
160{
161 bo->map_count++;
Dave Airlie1c2b3cb2010-10-04 16:26:46 +1000162 return 0;
John Doe40181ae2010-09-30 17:53:36 -0400163}
164
165static inline void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo)
166{
167 bo->map_count--;
168 assert(bo->map_count >= 0);
169}
170
Jerome Glissefd266ec2010-09-17 10:41:50 -0400171#endif