libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
dma.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
27#ifndef __WF_LIBWS_DMA_H__
28#define __WF_LIBWS_DMA_H__
29
30#include <stdint.h>
31#include <wonderful.h>
32#include "hardware.h"
33#include "util.h"
34
40static inline void ws_dma_set_sourcep(const void __far *src) {
41 outportw(IO_DMA_SOURCE_L, (FP_SEG(src) << 4) + FP_OFF(src));
42 outportb(IO_DMA_SOURCE_H, FP_SEG(src) >> 12);
43}
44
45static inline void ws_dma_set_sourcei(uint32_t src) {
46 outportw(IO_DMA_SOURCE_L, src);
47 outportb(IO_DMA_SOURCE_H, src >> 16);
48}
49
50#define ws_dma_set_source(src) _Generic((src), \
51 int8_t: ws_dma_set_sourcei, \
52 int16_t: ws_dma_set_sourcei, \
53 int32_t: ws_dma_set_sourcei, \
54 uint8_t: ws_dma_set_sourcei, \
55 uint16_t: ws_dma_set_sourcei, \
56 uint32_t: ws_dma_set_sourcei, \
57 default: ws_dma_set_sourcep \
58)(src)
59
60static inline void ws_sdma_set_sourcep(const void __far *src) {
61 outportw(IO_SDMA_SOURCE_L, (FP_SEG(src) << 4) + FP_OFF(src));
62 outportb(IO_SDMA_SOURCE_H, FP_SEG(src) >> 12);
63}
64
65static inline void ws_sdma_set_sourcei(uint32_t src) {
66 outportw(IO_SDMA_SOURCE_L, src);
67 outportb(IO_SDMA_SOURCE_H, src >> 16);
68}
69
70#define ws_sdma_set_source(src) _Generic((src), \
71 int8_t: ws_sdma_set_sourcei, \
72 int16_t: ws_sdma_set_sourcei, \
73 int32_t: ws_sdma_set_sourcei, \
74 uint8_t: ws_sdma_set_sourcei, \
75 uint16_t: ws_sdma_set_sourcei, \
76 uint32_t: ws_sdma_set_sourcei, \
77 default: ws_sdma_set_sourcep \
78)(src)
79
80static inline void ws_sdma_set_length(uint32_t length) {
81 outportw(IO_SDMA_LENGTH_L, length);
82 outportb(IO_SDMA_LENGTH_H, length >> 16);
83}
84
94void ws_dma_copy_words_linear(void __wf_iram* dest, uint32_t src, uint16_t length);
95
105static inline void ws_dma_copy_words(void __wf_iram* dest, const void __far* src, uint16_t length) {
106 ws_dma_copy_words_linear(dest, ws_ptr_to_linear(src), length);
107}
108
116void ws_dma_opt_copy_words(void __wf_iram* dest, const void __far* src, uint16_t length);
117
120#endif /* __WF_LIBWS_DMA_H__ */
static void ws_dma_set_sourcei(uint32_t src)
Definition dma.h:45
void ws_dma_opt_copy_words(void __wf_iram *dest, const void __far *src, uint16_t length)
Copy words from a source pointer to a destination pointer, using DMA if present.
static void ws_dma_set_sourcep(const void __far *src)
Definition dma.h:40
static void ws_sdma_set_length(uint32_t length)
Definition dma.h:80
static void ws_sdma_set_sourcei(uint32_t src)
Definition dma.h:65
static void ws_sdma_set_sourcep(const void __far *src)
Definition dma.h:60
void ws_dma_copy_words_linear(void __wf_iram *dest, uint32_t src, uint16_t length)
Copy words from a source linear address to a destination pointer using DMA.
static void ws_dma_copy_words(void __wf_iram *dest, const void __far *src, uint16_t length)
Copy words from a source pointer to a destination pointer using DMA.
Definition dma.h:105
#define IO_SDMA_LENGTH_H
Definition hardware.h:183
#define IO_SDMA_SOURCE_L
Definition hardware.h:180
#define IO_DMA_SOURCE_L
Definition hardware.h:174
#define IO_DMA_SOURCE_H
Definition hardware.h:175
#define IO_SDMA_LENGTH_L
Definition hardware.h:182
#define IO_SDMA_SOURCE_H
Definition hardware.h:181
static uint32_t ws_ptr_to_linear(const void __far *src)
Definition util.h:33