1 /* 2 * Generic DMA support. 3 * 4 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/cpm-generic.h> 32 #include <l4/re/c/dma_space.h> 33 34 // DMA channel. 35 36 class Dma_channel 37 { 38 public: 39 virtual unsigned int transfer(uint32_t source, uint32_t destination, 40 unsigned int count, 41 bool source_increment, bool destination_increment, 42 uint8_t source_width, uint8_t destination_width, 43 uint8_t transfer_unit_size, 44 int type, 45 l4_addr_t desc_vaddr = 0, 46 l4re_dma_space_dma_addr_t desc_paddr = 0) = 0; 47 48 virtual unsigned int wait() = 0; 49 }; 50 51 // DMA device control. 52 53 class Dma_chip 54 { 55 public: 56 virtual void disable() = 0; 57 58 virtual void enable() = 0; 59 60 virtual Dma_channel *get_channel(uint8_t channel, l4_cap_idx_t irq) = 0; 61 62 // Transaction control. 63 64 virtual void ack_irq(uint8_t channel) 65 { 66 (void) channel; 67 } 68 69 virtual void clear_errors() 70 { 71 } 72 73 virtual bool error() 74 { 75 return false; 76 } 77 78 virtual bool halted() 79 { 80 return false; 81 } 82 83 virtual void commit_descriptor(uint8_t channel) 84 { 85 (void) channel; 86 } 87 88 virtual bool have_interrupt(uint8_t channel) = 0; 89 }; 90 91 // Generic access to the DMA abstraction. 92 93 Dma_chip *new_dma_chip(const char *name, l4_addr_t start, l4_addr_t end, Cpm_chip *cpm); 94 95 #endif /* __cplusplus */