From 4b91bf77e8d9ec819d90d32a2a7f1223d62ee3b0 Mon Sep 17 00:00:00 2001 From: Jerome Glisse Date: Wed, 17 Feb 2010 23:40:58 +0100 Subject: group private into radeon_device.h --- lwrapper.h | 53 ----------------------------- r600_atom.c | 20 +++++------ r600_atom.h | 2 +- r600_batch.c | 33 +++++------------- radeon.h | 5 ++- radeon_atom.c | 50 +++++++++------------------- radeon_atom.h | 82 --------------------------------------------- radeon_device.c | 20 ----------- radeon_device.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++---------- test.c | 1 - 10 files changed, 122 insertions(+), 245 deletions(-) delete mode 100644 radeon_atom.h diff --git a/lwrapper.h b/lwrapper.h index 2d7b5aa..f113497 100644 --- a/lwrapper.h +++ b/lwrapper.h @@ -17,58 +17,5 @@ #ifndef LWRAPPER_H #define LWRAPPER_H -#include -#include -#include -#include -#include "xf86drm.h" -#include "radeon_bo.h" -#include "radeon_drm.h" - -typedef uint8_t u8; -typedef uint32_t u32; -typedef uint64_t u64; -#define GFP_KERNEL 0 -#define kmalloc(s, gfp) malloc(s) -#define kfree(p) free(p) - -struct idr { - u32 cid; -}; - -struct mutex { - int lock; -}; - -#define mutex_init(ptr) -#define mutex_lock(ptr) -#define mutex_unlock(ptr) - -extern int idr_pre_get(struct idr *idp, int gfp_mask); -extern int idr_get_new(struct idr *idp, void *ptr, int *id); -extern void idr_destroy(struct idr *idp); -extern void idr_init(struct idr *idp); - -#include "list.h" -#define dev_err(d, p, args...) fprintf(stderr, p, ##args) - -struct kref { - int refcount; -}; - -void kref_set(struct kref *kref, int num); -void kref_init(struct kref *kref); -void kref_get(struct kref *kref); -int kref_put(struct kref *kref, void (*release) (struct kref *kref)); -/** - * container_of - cast a member of a structure out to the containing structure - * @ptr: the pointer to the member. - * @type: the type of the container struct this is embedded in. - * @member: the name of the member within the struct. - * - */ -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) #endif diff --git a/r600_atom.c b/r600_atom.c index 4e849a0..8008cc3 100644 --- a/r600_atom.c +++ b/r600_atom.c @@ -49,7 +49,7 @@ int r600_cb_create(struct radeon_device *rdev, struct radeon_atom *atom, void *d return -ENOMEM; memcpy(cb, data, sizeof(struct drm_r600_cb)); atom->state = cb; - r = radeon_atom_init(atom, &rdev->idr, &r600_cb_emit); + r = radeon_atom_init(atom, &r600_cb_emit); if (r) return r; atom->nflushes = 1; @@ -230,7 +230,7 @@ int r600_cb_cntl_create(struct radeon_device *rdev, struct radeon_atom *atom, vo return -ENOMEM; memcpy(cb_cntl, data, sizeof(struct drm_r600_cb_cntl)); atom->state = cb_cntl; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; /* CB_TARGET_MASK */ @@ -286,7 +286,7 @@ int r600_pa_create(struct radeon_device *rdev, struct radeon_atom *atom, void *d return -ENOMEM; memcpy(pa, data, sizeof(struct drm_r600_pa)); atom->state = pa; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; /* PA_SC_MPASS_PS_CNTL */ @@ -376,7 +376,7 @@ int r600_vport_create(struct radeon_device *rdev, struct radeon_atom *atom, void return -ENOMEM; memcpy(vport, data, sizeof(struct drm_r600_vport)); atom->state = vport; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; /* PA_SC_VPORT_ZMIN_0 */ @@ -435,7 +435,7 @@ int r600_blend_create(struct radeon_device *rdev, struct radeon_atom *atom, void return -ENOMEM; memcpy(blend, data, sizeof(struct drm_r600_blend)); atom->state = blend; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; /* CB_BLEND0_CONTROL */ @@ -470,7 +470,7 @@ int r600_constants_create(struct radeon_device *rdev, struct radeon_atom *atom, return -ENOMEM; memcpy(constants, data, sizeof(struct drm_r600_constants)); atom->state = constants; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; if ((constants->nconstants & 0x3) || (constants->offset & 0x3)) { @@ -518,7 +518,7 @@ int r600_db_create(struct radeon_device *rdev, struct radeon_atom *atom, void *d return -ENOMEM; memcpy(db, data, sizeof(struct drm_r600_db)); atom->state = db; - r = radeon_atom_init(atom, &rdev->idr, &r600_db_emit); + r = radeon_atom_init(atom, &r600_db_emit); if (r) return r; atom->bo[0] = radeon_bo_lookup(rdev, db->db_handle); @@ -626,7 +626,7 @@ int r600_db_cntl_create(struct radeon_device *rdev, struct radeon_atom *atom, vo return -ENOMEM; memcpy(db_cntl, data, sizeof(struct drm_r600_db_cntl)); atom->state = db_cntl; - r = radeon_atom_init(atom, &rdev->idr, &radeon_atom_emit_default); + r = radeon_atom_init(atom, &radeon_atom_emit_default); if (r) return r; /* DB_STENCIL_CLEAR */ @@ -704,7 +704,7 @@ int r600_vs_shader_create(struct radeon_device *rdev, struct radeon_atom *atom, return -ENOMEM; memcpy(vs_shader, data, sizeof(struct drm_r600_vs_shader)); atom->state = vs_shader; - r = radeon_atom_init(atom, &rdev->idr, &r600_vs_shader_emit); + r = radeon_atom_init(atom, &r600_vs_shader_emit); if (r) return r; /* SQ_PGM_START_FS */ @@ -797,7 +797,7 @@ int r600_ps_shader_create(struct radeon_device *rdev, struct radeon_atom *atom, return -ENOMEM; memcpy(ps_shader, data, sizeof(struct drm_r600_ps_shader)); atom->state = ps_shader; - r = radeon_atom_init(atom, &rdev->idr, &r600_ps_shader_emit); + r = radeon_atom_init(atom, &r600_ps_shader_emit); if (r) return r; /* SQ_PGM_START_PS */ diff --git a/r600_atom.h b/r600_atom.h index e7440a2..ab5c61d 100644 --- a/r600_atom.h +++ b/r600_atom.h @@ -18,7 +18,7 @@ #define R600_ATOM_H #include "r600_atom_kernel.h" - +#include "list.h" struct radeon_device; diff --git a/r600_batch.c b/r600_batch.c index 90881d9..9e87d20 100644 --- a/r600_batch.c +++ b/r600_batch.c @@ -148,7 +148,7 @@ static void r600_batches_clear_locked(struct radeon_device *rdev, struct r600_ba list_del(&batch->list); radeon_bo_unmap(batch->shaders); radeon_bo_unref(batch->shaders); - kfree(batch); + free(batch); } INIT_LIST_HEAD(&batches->batches); for (i = 0; i < batches->nfs_resources; i++) { @@ -215,29 +215,25 @@ int r600_batches_queue(struct radeon_device *rdev, struct drm_r600_batch *batch) if (r) return r; memcpy(&rbatch->inputs, &batch->inputs, sizeof(struct r600_vs_input)); - mutex_lock(&rdev->mutex); i = 0; if (batch->blend == NULL || batch->cb_cntl == NULL || batch->pa == NULL || batch->vport == NULL || batch->cb == NULL || batch->db_cntl == NULL || batch->vs_shader == NULL || batch->ps_shader == NULL) { - mutex_unlock(&rdev->mutex); free(rbatch); - dev_err(rdev->dev, "invalid batch\n"); + fprintf(stderr, "invalid batch\n"); return -EINVAL; } rbatch->shaders = radeon_bo_open(rdev->radeon->bom, 0, 4096 * 16, 0, RADEON_GEM_DOMAIN_GTT, 0); if (rbatch->shaders == NULL) { - mutex_unlock(&rdev->mutex); - kfree(rbatch); - dev_err(rdev->dev, "can't create buffer for shaders\n"); + free(rbatch); + fprintf(stderr, "can't create buffer for shaders\n"); return -ENOMEM; } r = radeon_bo_map(rbatch->shaders, 1); if (r) { - mutex_unlock(&rdev->mutex); - kfree(rbatch); - dev_err(rdev->dev, "can't map buffer for shaders\n"); + free(rbatch); + fprintf(stderr, "can't map buffer for shaders\n"); return r; } rbatch->atoms[i++] = batch->blend; kref_get(&batch->blend->kref); @@ -279,8 +275,7 @@ reprocess: goto out_err; } rbatch->nflushes += rbatch->atoms[i]->nbo; - if (batches->last_id[i] != rbatch->atoms[i]->id) - rbatch->emit_atoms[rbatch->nemit_atoms++] = rbatch->atoms[i]; + rbatch->emit_atoms[rbatch->nemit_atoms++] = rbatch->atoms[i]; } } /* add flush */ @@ -291,7 +286,7 @@ reprocess: * not happen */ if (rbatch->npkts > batches->ib->length_dw) { - dev_err(rdev->dev, "single batch to big (%d) to fit into ib (%d)\n", + fprintf(stderr, "single batch to big (%d) to fit into ib (%d)\n", rbatch->npkts, batches->ib->length_dw); goto out_err; } @@ -318,14 +313,12 @@ reprocess: } batches->npkts += rbatch->npkts; list_add_tail(&rbatch->list, &batches->batches); - mutex_unlock(&rdev->mutex); return 0; out_err: for (i = 0; i < R600_BATCH_NATOMS; i++) { if (rbatch->atoms[i]) radeon_atom_put(rbatch->atoms[i]); } - mutex_unlock(&rdev->asic.r700.atom.mutex); radeon_bo_unmap(rbatch->shaders); radeon_bo_unref(rbatch->shaders); free(rbatch); @@ -357,16 +350,12 @@ int r600_batches_flush(struct radeon_device *rdev) { int r; - mutex_lock(&rdev->mutex); r = r600_batches_flush_locked(rdev, &rdev->batches); - mutex_unlock(&rdev->mutex); return r; } int r600_atoms_init(struct radeon_device *rdev) { - mutex_init(&rdev->mutex); - idr_init(&rdev->idr); rdev->npipes = 2; rdev->nbanks = 4; rdev->group_bytes = 256; @@ -375,10 +364,7 @@ int r600_atoms_init(struct radeon_device *rdev) void r600_atoms_release(struct radeon_device *rdev) { - mutex_lock(&rdev->mutex); r600_batches_cleanup_locked(rdev, &rdev->batches); - idr_destroy(&rdev->idr); - mutex_unlock(&rdev->mutex); } /* @@ -399,7 +385,6 @@ int r600_atom_create(struct radeon_device *rdev, struct drm_radeon_atom *patom, patom->id = 0; radeon_device_set_bo_list(rdev, cont->nbo, cont->bo); atom->type = patom->type; - mutex_lock(&rdev->mutex); switch (patom->type) { case R600_ATOM_CB: r = r600_cb_create(rdev, atom, cont->data); @@ -452,11 +437,9 @@ int r600_atom_create(struct radeon_device *rdev, struct drm_radeon_atom *patom, return r; break; default: - dev_err(rdev->dev, "unknown R600 atom type 0x%08X\n", patom->type); return -EINVAL; } patom->id = atom->id; *atomptr = atom; - mutex_unlock(&rdev->mutex); return 0; } diff --git a/radeon.h b/radeon.h index 942a625..9afa5dc 100644 --- a/radeon.h +++ b/radeon.h @@ -22,9 +22,12 @@ #include "xf86drmMode.h" #include "radeon_bo.h" #include "radeon_cs.h" -#include "lwrapper.h" #include +typedef uint8_t u8; +typedef uint32_t u32; +typedef uint64_t u64; + struct radeon_mode { drmModeModeInfo info; u32 pitch; diff --git a/radeon_atom.c b/radeon_atom.c index 9904b33..e27116f 100644 --- a/radeon_atom.c +++ b/radeon_atom.c @@ -16,9 +16,7 @@ */ #include "radeon_device.h" -int radeon_atom_init(struct radeon_atom *atom, - struct idr *idp, - radeon_atom_emit_t emit) +int radeon_atom_init(struct radeon_atom *atom, radeon_atom_emit_t emit) { int r; @@ -26,34 +24,6 @@ int radeon_atom_init(struct radeon_atom *atom, kref_init(&atom->kref); atom->emit = emit; atom->nflushes = 0; - r = idr_pre_get(idp, GFP_KERNEL); - if (r) - return r; - r = idr_get_new(idp, atom, &atom->id); - if (r) - return r; - return 0; -} - -int radeon_atom_find_locked(struct list_head *atoms, u32 id, - u32 type, struct radeon_atom **atom) -{ - struct radeon_atom *i; - - *atom = NULL; - list_for_each_entry(i, atoms, list) { - if (i->id == id) - break; - } - if (i == (struct radeon_atom*)atoms) - return -EINVAL; - if (i->type != type) { - dev_err(rdev->dev, "atom(0x%08X, 0x%08X) not of type 0x%08X\n", - i->id, i->type, type); - return -EINVAL; - } - *atom = i; - kref_get(&i->kref); return 0; } @@ -86,10 +56,8 @@ int radeon_atom_flush_add(struct list_head *flushes, struct radeon_bo *bo, u32 f return 1; } -int radeon_atom_emit_default(struct radeon_device *rdev, - struct radeon_atom *atom, - void *data, - struct radeon_ib *ib) +int radeon_atom_emit_default(struct radeon_device *rdev, struct radeon_atom *atom, + void *data, struct radeon_ib *ib) { return radeon_ib_copy(ib, atom->pkts, atom->npkts); } @@ -129,3 +97,15 @@ void radeon_device_set_bo_list(struct radeon_device *rdev, u32 nbo, struct radeo memcpy(rdev->bo, bo, sizeof(void*) * nbo); rdev->nbo = nbo; } + +void radeon_atom_release(struct kref *kref) +{ + struct radeon_atom *atom = container_of(kref, struct radeon_atom, kref); + int i; + + for (i = 0; i < atom->nbo; i++) { + radeon_bo_unref(atom->bo[i]); + } + free(atom->state); + free(atom); +} diff --git a/radeon_atom.h b/radeon_atom.h deleted file mode 100644 index 7e5ba95..0000000 --- a/radeon_atom.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2010 Jerome Glisse - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#ifndef RADEON_ATOM_H -#define RADEON_ATOM_H - -#include "r600_winsys.h" - -struct radeon_device; -struct radeon_ib; -struct radeon_atom; - -struct radeon_atom_flush { - struct list_head list; - u32 flags; - struct radeon_bo *bo; -}; - -typedef int (*radeon_atom_emit_t)(struct radeon_device*, - struct radeon_atom*, - void *data, - struct radeon_ib*); - -struct radeon_atom { - struct list_head list; - struct kref kref; - u32 type; - u32 id; - u32 nflushes; - u32 npkts; - u32 nbo; - u32 pkts[256]; - struct radeon_bo *bo[32]; - u32 flags[32]; - void *state; - radeon_atom_emit_t emit; -}; - -extern int radeon_atom_init(struct radeon_atom *atom, - struct idr *idp, - radeon_atom_emit_t emit); -extern void radeon_atom_flush_cleanup(struct list_head *flushes); -extern int radeon_atom_flush_add(struct list_head *flushes, struct radeon_bo *bo, u32 flags); -extern int radeon_atom_find_locked(struct list_head *atoms, u32 id, - u32 type, struct radeon_atom **atom); -extern int radeon_atom_emit_default(struct radeon_device *rdev, - struct radeon_atom *atom, - void *data, - struct radeon_ib *ib); -static void radeon_atom_release(struct kref *kref) -{ - struct radeon_atom *atom = container_of(kref, struct radeon_atom, kref); - int i; - - for (i = 0; i < atom->nbo; i++) { - radeon_bo_unref(atom->bo[i]); - } - free(atom->state); - free(atom); -} -void radeon_device_set_bo_list(struct radeon_device *rdev, u32 nbo, struct radeon_bo **bo); - -static inline void radeon_atom_put(struct radeon_atom *atom) -{ - kref_put(&atom->kref, radeon_atom_release); -} -struct radeon_bo *radeon_bo_lookup(struct radeon_device *rdev, u32 handle); - -#endif diff --git a/radeon_device.c b/radeon_device.c index 73eceda..22490f3 100644 --- a/radeon_device.c +++ b/radeon_device.c @@ -114,26 +114,6 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib) return r; } -int idr_pre_get(struct idr *idp, int gfp_mask) -{ - return 0; -} - -int idr_get_new(struct idr *idp, void *ptr, int *id) -{ - *id = ++idp->cid; - return 0; -} - -void idr_destroy(struct idr *idp) -{ -} - -void idr_init(struct idr *idp) -{ - idp->cid = 0; -} - int radeon_device_init(struct radeon_device **rdev, struct radeon *radeon) { struct radeon_device *dev; diff --git a/radeon_device.h b/radeon_device.h index 94f6495..cd623b3 100644 --- a/radeon_device.h +++ b/radeon_device.h @@ -17,43 +17,110 @@ #ifndef RADEON_DEVICE_H #define RADEON_DEVICE_H +#include +#include +#include +#include +#include "xf86drm.h" +#include "radeon_bo.h" +#include "radeon_drm.h" #include "radeon.h" -#include "lwrapper.h" -#include "radeon_atom.h" +#include "list.h" +#include "r600_atom.h" -struct radeon_device; -struct radeon_ib; -struct radeon_atom; +/* UTILITIES END ************************************************************/ +#define GFP_KERNEL 0 +#define kmalloc(s, gfp) malloc(s) +#define kfree(p) free(p) +#define dev_err(d, p, args...) fprintf(stderr, p, ##args) + +struct kref { + int refcount; +}; -/* Wrapper to make it looks like kernel *************************************/ +void kref_set(struct kref *kref, int num); +void kref_init(struct kref *kref); +void kref_get(struct kref *kref); +int kref_put(struct kref *kref, void (*release) (struct kref *kref)); +/** + * container_of - cast a member of a structure out to the containing structure + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) #define radeon_bo_size(bo) ((bo)->size) +/* UTILITIES END ************************************************************/ + +struct radeon_device; + +struct radeon_ib { + u32 *ptr; + u32 cpkts; + u32 length_dw; + u32 *relocs; + u32 crelocs; + u32 nrelocs; +}; + +struct radeon_atom_flush { + struct list_head list; + u32 flags; + struct radeon_bo *bo; +}; + +typedef int (*radeon_atom_emit_t)(struct radeon_device*, + struct radeon_atom*, + void *data, + struct radeon_ib*); + +struct radeon_atom { + struct list_head list; + struct kref kref; + u32 type; + u32 id; + u32 nflushes; + u32 npkts; + u32 nbo; + u32 pkts[256]; + struct radeon_bo *bo[32]; + u32 flags[32]; + void *state; + radeon_atom_emit_t emit; +}; + struct radeon_device { struct radeon *radeon; int fd; struct radeon_bo *bo[32]; u32 nbo; - struct idr idr; - struct mutex mutex; struct r600_batches batches; unsigned npipes; unsigned nbanks; unsigned group_bytes; }; -struct radeon_ib { - u32 *ptr; - u32 cpkts; - u32 length_dw; - u32 *relocs; - u32 crelocs; - u32 nrelocs; -}; - extern u32 radeon_ib_reloc(struct radeon_ib *ib, struct radeon_bo *bo, u32 d); extern int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib); extern void radeon_ib_free(struct radeon_ib *ib); extern int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib); +extern int radeon_atom_init(struct radeon_atom *atom, radeon_atom_emit_t emit); +extern void radeon_atom_flush_cleanup(struct list_head *flushes); +extern int radeon_atom_flush_add(struct list_head *flushes, struct radeon_bo *bo, u32 flags); +extern int radeon_atom_emit_default(struct radeon_device *rdev, struct radeon_atom *atom, + void *data, struct radeon_ib *ib); +extern void radeon_atom_release(struct kref *kref); +extern void radeon_device_set_bo_list(struct radeon_device *rdev, u32 nbo, struct radeon_bo **bo); +extern struct radeon_bo *radeon_bo_lookup(struct radeon_device *rdev, u32 handle); + +static inline void radeon_atom_put(struct radeon_atom *atom) +{ + kref_put(&atom->kref, radeon_atom_release); +} static inline int radeon_ib_begin(struct radeon_ib *ib, u32 ndw) { diff --git a/test.c b/test.c index 9e5db4b..17b87af 100644 --- a/test.c +++ b/test.c @@ -22,7 +22,6 @@ #include #include #include "radeon.h" -#include "radeon_atom.h" #include "r600_winsys.h" int r600_tri_flat(struct radeon *radeon); -- cgit v1.2.3