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.
22 #include <exec/memory.h>
23 #include <utility/hooks.h>
25 #include <proto/exec.h>
27 #include "linuxsupport.h"
30 #include "emu10kx-misc.h"
31 #include "pci_wrapper.h"
34 AllocPages( size_t size
, ULONG req
)
38 #if defined(__AMIGAOS4__) || defined(__AROS__)
40 // FIXME: This should be non-cachable, DMA-able memory
41 address
= AllocVec( size
+ PAGE_SIZE
+ sizeof(APTR
), MEMF_PUBLIC
);
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
;
51 // FIXME: This should be non-cachable, DMA-able memory
52 address
= AllocMem( size
+ PAGE_SIZE
- 1, req
& ~MEMF_CLEAR
);
57 FreeMem( address
, size
+ PAGE_SIZE
- 1 );
58 address
= AllocAbs( size
,
59 (void*) ((ULONG
) ( address
+ PAGE_SIZE
- 1 )
65 if( address
!= NULL
&& ( req
& MEMF_CLEAR
) )
67 memset( address
, 0, size
);
74 __get_free_page( unsigned int gfp_mask
)
76 return (unsigned long) AllocPages( PAGE_SIZE
, MEMF_PUBLIC
);
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]);
86 FreeMem( (void*) addr
, PAGE_SIZE
);
91 pci_alloc_consistent( void* pci_dev
, size_t size
, dma_addr_t
* dma_handle
)
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
);
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]);
111 FreeMem( addr
, size
);
112 // pci_free_dmamem( pci_dev, addr, size );