124722904SRudolf Cornelissen/*
224722904SRudolf Cornelissen	Copyright 1999, Be Incorporated.   All Rights Reserved.
324722904SRudolf Cornelissen	This file may be used under the terms of the Be Sample Code License.
424722904SRudolf Cornelissen
524722904SRudolf Cornelissen	other authors:
624722904SRudolf Cornelissen	Mark Watson
724722904SRudolf Cornelissen	Rudolf Cornelissen 3/2004
824722904SRudolf Cornelissen*/
924722904SRudolf Cornelissen
1024722904SRudolf Cornelissen#define MODULE_BIT 0x10000000
1124722904SRudolf Cornelissen
1224722904SRudolf Cornelissen#include "acc_std.h"
1324722904SRudolf Cornelissen
1424722904SRudolf Cornelissen
1524722904SRudolf Cornelissenstatic engine_token eng_engine_token = { 1, B_2D_ACCELERATION, NULL };
1624722904SRudolf Cornelissen
1724722904SRudolf Cornelissenuint32 ACCELERANT_ENGINE_COUNT(void)
1824722904SRudolf Cornelissen{
1924722904SRudolf Cornelissen	/* we have one acceleration engine */
2024722904SRudolf Cornelissen	return 1;
2124722904SRudolf Cornelissen}
2224722904SRudolf Cornelissen
2324722904SRudolf Cornelissenstatus_t ACQUIRE_ENGINE(uint32 capabilities, uint32 max_wait, sync_token *st, engine_token **et)
2424722904SRudolf Cornelissen{
2524722904SRudolf Cornelissen	/* acquire the shared benaphore */
2624722904SRudolf Cornelissen	AQUIRE_BEN(si->engine.lock)
2724722904SRudolf Cornelissen	/* sync if required */
2824722904SRudolf Cornelissen	if (st) SYNC_TO_TOKEN(st);
2924722904SRudolf Cornelissen
3024722904SRudolf Cornelissen	/* return an engine token */
3124722904SRudolf Cornelissen	*et = &eng_engine_token;
3224722904SRudolf Cornelissen	return B_OK;
3324722904SRudolf Cornelissen}
3424722904SRudolf Cornelissen
3524722904SRudolf Cornelissenstatus_t RELEASE_ENGINE(engine_token *et, sync_token *st)
3624722904SRudolf Cornelissen{
3724722904SRudolf Cornelissen	/* update the sync token, if any */
3824722904SRudolf Cornelissen	if (st) GET_SYNC_TOKEN(et,st);
3924722904SRudolf Cornelissen
4024722904SRudolf Cornelissen	/* release the shared benaphore */
4124722904SRudolf Cornelissen	RELEASE_BEN(si->engine.lock)
4224722904SRudolf Cornelissen	return B_OK;
4324722904SRudolf Cornelissen}
4424722904SRudolf Cornelissen
4524722904SRudolf Cornelissenvoid WAIT_ENGINE_IDLE(void)
4624722904SRudolf Cornelissen{
4724722904SRudolf Cornelissen	/*wait for the engine to be totally idle*/
4824722904SRudolf Cornelissen	eng_acc_wait_idle();
4924722904SRudolf Cornelissen}
5024722904SRudolf Cornelissen
5124722904SRudolf Cornelissenstatus_t GET_SYNC_TOKEN(engine_token *et, sync_token *st)
5224722904SRudolf Cornelissen{
5324722904SRudolf Cornelissen	/* engine count will always be zero: we don't support syncing to token (yet) */
5424722904SRudolf Cornelissen	st->engine_id = et->engine_id;
5524722904SRudolf Cornelissen	st->counter = si->engine.count;
5624722904SRudolf Cornelissen	return B_OK;
5724722904SRudolf Cornelissen}
5824722904SRudolf Cornelissen
5924722904SRudolf Cornelissenstatus_t SYNC_TO_TOKEN(sync_token *st)
6024722904SRudolf Cornelissen{
6124722904SRudolf Cornelissen	/* wait until the engine is totally idle: we don't support syncing to token (yet) */
6224722904SRudolf Cornelissen	/* note:
6324722904SRudolf Cornelissen	 * AFAIK in order to be able to setup sync_to_token, we'd need a circular fifo
6424722904SRudolf Cornelissen	 * buffer in (main) memory instead of directly programming the GPU fifo so we
6524722904SRudolf Cornelissen	 * can tell (via a hardware maintained pointer into this circular fifo) where
6624722904SRudolf Cornelissen	 * the acc engine is with executing commands! */
6724722904SRudolf Cornelissen	WAIT_ENGINE_IDLE();
6824722904SRudolf Cornelissen
6924722904SRudolf Cornelissen	return B_OK;
7024722904SRudolf Cornelissen}