+ exec* functions
[meinos.git] / apps / include / dma.h
blobae56654661dad7d6c0048bec7944b8b3e0573404
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _DMA_H_
20 #define _DMA_H_
22 #include <sys/types.h>
23 #include <rpc.h>
24 #include <misc.h>
25 #include <limits.h>
26 #include <syscall.h>
28 #define DMA_PAGE_SIZE PAGE_SIZE
29 #define DMA_MAXCOUNT 65536
31 // Device => Memory
32 #define DMA_MODE_READ (1 << 2)
33 // Memory => Device
34 #define DMA_MODE_WRITE (2 << 2)
35 #define DMA_MODE_ON_DEMAND (0 << 6)
36 #define DMA_MODE_SINGLE (1 << 6)
37 #define DMA_MODE_BLOCK (2 << 6)
39 /**
40 * Allocates DMA memory
41 * @param size Size of DMA memory
42 * @return DMA memory
44 static inline void *dma_alloc(size_t size) {
45 return (void*)syscall_call(SYSCALL_MEM_DMA_ALLOC,1,((size-1)/DMA_PAGE_SIZE+1)*DMA_PAGE_SIZE);
48 /**
49 * Frees DMA memory
50 * @param buffer DMA memory
51 * @param size Size of DMA memory
52 * @return Success?
54 static inline int dma_free(void *buffer,size_t size) {
55 return syscall_call(SYSCALL_MEM_DMA_FREE,2,buffer,((size-1)/DMA_PAGE_SIZE+1)*DMA_PAGE_SIZE);
58 /**
59 * Checks if DMA channel is ready to use
60 * @param channel DMA channel
61 * @return If channel is ready to use
63 static inline int dma_isready(channel) {
64 return rpc_call("dma_isready",0,channel);
67 /**
68 * Start a DMA transfer
69 * @param channel DMA channel
70 * @param buf Buffer to read/write data from/to
71 * @param count How many bytes to transfer
72 * @param mode Transfer mode
73 * @return Success?
75 static inline int dma_start(int channel,void *buf,size_t count,int mode) {
76 return rpc_call("dma_start",0,channel,mem_getphysaddr(buf),count,mode);
79 /**
80 * Stops a DMA transfer
81 * @param channel DMA channel
82 * @return Success?
84 static inline int dma_stop(int channel) {
85 return rpc_call("dma_stop",0,channel);
88 #endif