/* * 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_DEVICE_H #define RADEON_DEVICE_H #include #include #include #include #include "xf86drm.h" #include "radeon_bo.h" #include "radeon_drm.h" #include "list.h" /* UTILITIES ****************************************************************/ 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) #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) );}) #define radeon_bo_size(bo) ((bo)->size) /* UTILITIES END ************************************************************/ #include "r600_atom_kernel.h" struct radeon_device; struct radeon_atom; struct drm_r600_vs_input; struct drm_r600_vs_shader; 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_create_t)(struct radeon_device*, struct radeon_atom*, void*); typedef int (*radeon_atom_emit_t)(struct radeon_device*, struct radeon_atom*, void*, 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 r600_atom_funcs { u32 type; u32 size; radeon_atom_create_t create; radeon_atom_emit_t emit; }; struct r600_vs_buffer { struct drm_r600_vs_buffer drm; struct radeon_bo *bo; }; struct r600_vs_input { struct drm_r600_vs_input drm; struct radeon_bo *bo[32]; u32 nbo; }; struct r600_batch { struct list_head list; struct list_head pre_flushes; struct list_head post_flushes; struct radeon_atom *atoms[R600_BATCH_NATOMS]; struct radeon_atom *emit_atoms[R600_BATCH_NATOMS]; u32 nemit_atoms; u32 nflushes; u32 npkts; struct radeon_bo *shaders; u32 shaders_idx; u32 nfs_resources; struct r600_vs_input inputs; }; struct r600_batches { struct radeon_ib *ib; u32 npkts; struct list_head batches; u32 nfs_resources; struct r600_vs_buffer fs_resource[160]; u32 last_id[R600_BATCH_NATOMS]; }; struct radeon_device { int fd; struct radeon_bo *bo[32]; u32 nbo; struct r600_batches batches; unsigned npipes; unsigned nbanks; unsigned group_bytes; struct radeon_bo_manager *bom; }; 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 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); extern u64 crc_64(void *d, size_t len); /* R700 */ extern void r700_batches_states_default(struct radeon_device *rdev, struct r600_batches *batches); 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) { if ((ib->cpkts + ndw) > ib->length_dw) return -ENOMEM; return 0; } static inline int radeon_ib_copy(struct radeon_ib *ib, u32 *pkts, u32 ndw) { if ((ib->cpkts + ndw) > ib->length_dw) { fprintf(stderr, "IB FULL !\n"); return -ENOMEM; } memcpy(&ib->ptr[ib->cpkts], pkts, ndw * 4); ib->cpkts += ndw; return 0; } #endif