1091b52d5Sshatty/*
2091b52d5Sshatty	Copyright 1999, Be Incorporated.   All Rights Reserved.
3091b52d5Sshatty	This file may be used under the terms of the Be Sample Code License.
4091b52d5Sshatty
52e66094aSRudolf Cornelissen	other authors:
62e66094aSRudolf Cornelissen	Mark Watson
72e66094aSRudolf Cornelissen	Rudolf Cornelissen 3/2004
8091b52d5Sshatty*/
9091b52d5Sshatty
10091b52d5Sshatty#define MODULE_BIT 0x10000000
11091b52d5Sshatty
12091b52d5Sshatty#include "acc_std.h"
13091b52d5Sshatty
14091b52d5Sshatty
15091b52d5Sshattystatic engine_token gx00_engine_token = { 1, B_2D_ACCELERATION, NULL };
16091b52d5Sshatty
172e66094aSRudolf Cornelissenuint32 ACCELERANT_ENGINE_COUNT(void)
182e66094aSRudolf Cornelissen{
192e66094aSRudolf Cornelissen	/* we have one acceleration engine */
20091b52d5Sshatty	return 1;
21091b52d5Sshatty}
22091b52d5Sshatty
232e66094aSRudolf Cornelissenstatus_t ACQUIRE_ENGINE(uint32 capabilities, uint32 max_wait, sync_token *st, engine_token **et)
242e66094aSRudolf Cornelissen{
25091b52d5Sshatty	/* acquire the shared benaphore */
26091b52d5Sshatty	AQUIRE_BEN(si->engine.lock)
27091b52d5Sshatty	/* sync if required */
28091b52d5Sshatty	if (st) SYNC_TO_TOKEN(st);
29091b52d5Sshatty
30091b52d5Sshatty	/* return an engine token */
31091b52d5Sshatty	*et = &gx00_engine_token;
32091b52d5Sshatty	return B_OK;
33091b52d5Sshatty}
34091b52d5Sshatty
352e66094aSRudolf Cornelissenstatus_t RELEASE_ENGINE(engine_token *et, sync_token *st)
362e66094aSRudolf Cornelissen{
37091b52d5Sshatty	/* update the sync token, if any */
382e66094aSRudolf Cornelissen	if (st) GET_SYNC_TOKEN(et,st);
39091b52d5Sshatty
40091b52d5Sshatty	/* release the shared benaphore */
41091b52d5Sshatty	RELEASE_BEN(si->engine.lock)
42091b52d5Sshatty	return B_OK;
43091b52d5Sshatty}
44091b52d5Sshatty
452e66094aSRudolf Cornelissenvoid WAIT_ENGINE_IDLE(void)
462e66094aSRudolf Cornelissen{
47091b52d5Sshatty	/*wait for the engine to be totally idle*/
48091b52d5Sshatty	gx00_acc_wait_idle();
49091b52d5Sshatty}
50091b52d5Sshatty
512e66094aSRudolf Cornelissenstatus_t GET_SYNC_TOKEN(engine_token *et, sync_token *st)
522e66094aSRudolf Cornelissen{
532e66094aSRudolf Cornelissen	/* engine count will always be zero: we don't support syncing to token (yet) */
54091b52d5Sshatty	st->engine_id = et->engine_id;
55091b52d5Sshatty	st->counter = si->engine.count;
56091b52d5Sshatty	return B_OK;
57091b52d5Sshatty}
58091b52d5Sshatty
592e66094aSRudolf Cornelissenstatus_t SYNC_TO_TOKEN(sync_token *st)
602e66094aSRudolf Cornelissen{
612e66094aSRudolf Cornelissen	/* wait until the engine is totally idle: we don't support syncing to token (yet) */
622e66094aSRudolf Cornelissen	/* note:
632e66094aSRudolf Cornelissen	 * AFAIK in order to be able to setup sync_to_token, we'd need a circular fifo
642e66094aSRudolf Cornelissen	 * buffer in (main) memory instead of directly programming the GPU fifo so we
652e66094aSRudolf Cornelissen	 * can tell (via a hardware maintained pointer into this circular fifo) where
662e66094aSRudolf Cornelissen	 * the acc engine is with executing commands! */
67091b52d5Sshatty	WAIT_ENGINE_IDLE();
68091b52d5Sshatty
69091b52d5Sshatty	return B_OK;
70091b52d5Sshatty}
71