108705d96Sshatty/*
208705d96Sshatty	Copyright 1999, Be Incorporated.   All Rights Reserved.
308705d96Sshatty	This file may be used under the terms of the Be Sample Code License.
408705d96Sshatty
5599fbbf0SRudolf Cornelissen	other authors:
6599fbbf0SRudolf Cornelissen	Mark Watson
76042b7b6SRudolf Cornelissen	Rudolf Cornelissen 3/2004-3/2009
808705d96Sshatty*/
908705d96Sshatty
10dd43fd34SRudolf Cornelissen/*
11dd43fd34SRudolf Cornelissen	note:
12dd43fd34SRudolf Cornelissen	attempting DMA on NV40 and higher because without it I can't get it going ATM.
13dd43fd34SRudolf Cornelissen	Later on this can become a nv.settings switch, and maybe later we can even
14dd43fd34SRudolf Cornelissen	forget about non-DMA completely (depends on 3D acceleration attempts).
15dd43fd34SRudolf Cornelissen*/
16dd43fd34SRudolf Cornelissen
1708705d96Sshatty#define MODULE_BIT 0x10000000
1808705d96Sshatty
1908705d96Sshatty#include "acc_std.h"
2008705d96Sshatty
2108705d96Sshatty
2208705d96Sshattystatic engine_token nv_engine_token = { 1, B_2D_ACCELERATION, NULL };
2308705d96Sshatty
24599fbbf0SRudolf Cornelissenuint32 ACCELERANT_ENGINE_COUNT(void)
25599fbbf0SRudolf Cornelissen{
26599fbbf0SRudolf Cornelissen	/* we have one acceleration engine */
2708705d96Sshatty	return 1;
2808705d96Sshatty}
2908705d96Sshatty
301554e5cbSRudolf Cornelissenstatus_t ACQUIRE_ENGINE_PIO(uint32 capabilities, uint32 max_wait, sync_token *st, engine_token **et)
31599fbbf0SRudolf Cornelissen{
3208705d96Sshatty	/* acquire the shared benaphore */
3308705d96Sshatty	AQUIRE_BEN(si->engine.lock)
3408705d96Sshatty	/* sync if required */
3508705d96Sshatty	if (st) SYNC_TO_TOKEN(st);
3608705d96Sshatty
376042b7b6SRudolf Cornelissen	/* make sure all needed engine cmd's are mapped to the FIFO if acceleration isn't blocked */
386042b7b6SRudolf Cornelissen	if (!si->settings.block_acc) nv_acc_assert_fifo();
391554e5cbSRudolf Cornelissen
401554e5cbSRudolf Cornelissen	/* return an engine token */
411554e5cbSRudolf Cornelissen	*et = &nv_engine_token;
421554e5cbSRudolf Cornelissen	return B_OK;
431554e5cbSRudolf Cornelissen}
441554e5cbSRudolf Cornelissen
451554e5cbSRudolf Cornelissenstatus_t ACQUIRE_ENGINE_DMA(uint32 capabilities, uint32 max_wait, sync_token *st, engine_token **et)
461554e5cbSRudolf Cornelissen{
471554e5cbSRudolf Cornelissen	/* acquire the shared benaphore */
481554e5cbSRudolf Cornelissen	AQUIRE_BEN(si->engine.lock)
491554e5cbSRudolf Cornelissen	/* sync if required */
501554e5cbSRudolf Cornelissen	if (st) SYNC_TO_TOKEN(st);
511554e5cbSRudolf Cornelissen
526042b7b6SRudolf Cornelissen	/* make sure all needed engine cmd's are mapped to the FIFO if acceleration isn't blocked */
536042b7b6SRudolf Cornelissen	if (!si->settings.block_acc) nv_acc_assert_fifo_dma();
543c327b53SRudolf Cornelissen
5508705d96Sshatty	/* return an engine token */
5608705d96Sshatty	*et = &nv_engine_token;
5708705d96Sshatty	return B_OK;
5808705d96Sshatty}
5908705d96Sshatty
60599fbbf0SRudolf Cornelissenstatus_t RELEASE_ENGINE(engine_token *et, sync_token *st)
61599fbbf0SRudolf Cornelissen{
6208705d96Sshatty	/* update the sync token, if any */
63599fbbf0SRudolf Cornelissen	if (st) GET_SYNC_TOKEN(et,st);
6408705d96Sshatty
6508705d96Sshatty	/* release the shared benaphore */
6608705d96Sshatty	RELEASE_BEN(si->engine.lock)
6708705d96Sshatty	return B_OK;
6808705d96Sshatty}
6908705d96Sshatty
70599fbbf0SRudolf Cornelissenvoid WAIT_ENGINE_IDLE(void)
71599fbbf0SRudolf Cornelissen{
726042b7b6SRudolf Cornelissen	/* do nothing if acceleration is te be blocked */
736042b7b6SRudolf Cornelissen	if (si->settings.block_acc) return;
746042b7b6SRudolf Cornelissen
7567aa755bSRudolf Cornelissen	/*wait for the engine to be totally idle*/
76dd446dd3SRudolf Cornelissen	if (!si->settings.dma_acc)
77dd43fd34SRudolf Cornelissen		nv_acc_wait_idle();
78dd43fd34SRudolf Cornelissen	else
79dd43fd34SRudolf Cornelissen		nv_acc_wait_idle_dma();
8008705d96Sshatty}
8108705d96Sshatty
82599fbbf0SRudolf Cornelissenstatus_t GET_SYNC_TOKEN(engine_token *et, sync_token *st)
83599fbbf0SRudolf Cornelissen{
84599fbbf0SRudolf Cornelissen	/* engine count will always be zero: we don't support syncing to token (yet) */
8508705d96Sshatty	st->engine_id = et->engine_id;
8608705d96Sshatty	st->counter = si->engine.count;
8708705d96Sshatty	return B_OK;
8808705d96Sshatty}
8908705d96Sshatty
90599fbbf0SRudolf Cornelissenstatus_t SYNC_TO_TOKEN(sync_token *st)
91599fbbf0SRudolf Cornelissen{
92599fbbf0SRudolf Cornelissen	/* wait until the engine is totally idle: we don't support syncing to token (yet) */
93599fbbf0SRudolf Cornelissen	/* note:
94599fbbf0SRudolf Cornelissen	 * AFAIK in order to be able to setup sync_to_token, we'd need a circular fifo
95599fbbf0SRudolf Cornelissen	 * buffer in (main) memory instead of directly programming the GPU fifo so we
96599fbbf0SRudolf Cornelissen	 * can tell (via a hardware maintained pointer into this circular fifo) where
97599fbbf0SRudolf Cornelissen	 * the acc engine is with executing commands! */
9808705d96Sshatty	WAIT_ENGINE_IDLE();
9908705d96Sshatty
10008705d96Sshatty	return B_OK;
10108705d96Sshatty}
102