Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / EMU10kx / linuxsupport.c
blob9079f05332a36072a8e4daee98cdce0b60d12e2b
1 /*
2 emu10kx.audio - AHI driver for SoundBlaster Live! series
3 Copyright (C) 2002-2005 Martin Blom <martin@blom.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <config.h>
22 #include <exec/memory.h>
23 #include <utility/hooks.h>
25 #include <proto/exec.h>
27 #include "linuxsupport.h"
28 #include <string.h>
30 #include "emu10kx-misc.h"
31 #include "pci_wrapper.h"
33 static void*
34 AllocPages( size_t size, ULONG req )
36 void* address;
38 #if defined(__AMIGAOS4__) || defined(__AROS__)
39 unsigned long a;
40 // FIXME: This should be non-cachable, DMA-able memory
41 address = AllocVec( size + PAGE_SIZE + sizeof(APTR), MEMF_PUBLIC );
43 if( address != NULL )
45 a = (unsigned long) address;
46 a = (a + PAGE_SIZE - 1 + sizeof(APTR)) & ~(PAGE_SIZE - 1); //(((unsigned long) (a + 4096)) / 4096) * 4096; // get a 4K-aligned memory pointer
47 ((APTR *)a)[-1] = address;
48 address = (void *) a;
50 #else
51 // FIXME: This should be non-cachable, DMA-able memory
52 address = AllocMem( size + PAGE_SIZE - 1, req & ~MEMF_CLEAR );
54 if( address != NULL )
56 Forbid();
57 FreeMem( address, size + PAGE_SIZE - 1 );
58 address = AllocAbs( size,
59 (void*) ((ULONG) ( address + PAGE_SIZE - 1 )
60 & ~(PAGE_SIZE-1) ) );
61 Permit();
63 #endif
65 if( address != NULL && ( req & MEMF_CLEAR ) )
67 memset( address, 0, size );
70 return address;
73 unsigned long
74 __get_free_page( unsigned int gfp_mask )
76 return (unsigned long) AllocPages( PAGE_SIZE, MEMF_PUBLIC );
79 void
80 free_page( unsigned long addr )
82 // printf( "Freeing page at %08x\n", addr );
83 #if defined(__AMIGAOS4__) || defined(__AROS__)
84 if (addr) FreeVec(((APTR *)addr)[-1]);
85 #else
86 FreeMem( (void*) addr, PAGE_SIZE );
87 #endif
90 void*
91 pci_alloc_consistent( void* pci_dev, size_t size, dma_addr_t* dma_handle )
93 void* res;
95 // res = pci_alloc_dmamem( pci_dev, size );
96 res = (void*) AllocPages( size, MEMF_PUBLIC | MEMF_CLEAR );
98 *dma_handle = (dma_addr_t) ahi_pci_logic_to_physic_addr( res, pci_dev );
100 return res;
103 void
104 pci_free_consistent( void* pci_dev, size_t size, void* addr, dma_addr_t dma_handle )
106 // printf( "Freeing pages (%d bytes) at %08x\n", size, addr );
108 #if defined(__AMIGAOS4__) || defined(__AROS__)
109 if (addr) FreeVec(((APTR *)addr)[-1]);
110 #else
111 FreeMem( addr, size );
112 // pci_free_dmamem( pci_dev, addr, size );
113 #endif