1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/dma/include/dma-generic.h Sat Apr 27 23:46:28 2024 +0200
1.3 @@ -0,0 +1,91 @@
1.4 +/*
1.5 + * Generic DMA support.
1.6 + *
1.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/sys/types.h>
1.28 +#include <stdint.h>
1.29 +
1.30 +
1.31 +
1.32 +#ifdef __cplusplus
1.33 +
1.34 +#include <l4/devices/cpm-generic.h>
1.35 +#include <l4/re/c/dma_space.h>
1.36 +
1.37 +// DMA channel.
1.38 +
1.39 +class Dma_channel
1.40 +{
1.41 +public:
1.42 + virtual unsigned int transfer(uint32_t source, uint32_t destination,
1.43 + unsigned int count,
1.44 + bool source_increment, bool destination_increment,
1.45 + uint8_t source_width, uint8_t destination_width,
1.46 + uint8_t transfer_unit_size,
1.47 + int type,
1.48 + l4_addr_t desc_vaddr = 0,
1.49 + l4re_dma_space_dma_addr_t desc_paddr = 0) = 0;
1.50 +
1.51 + virtual unsigned int wait() = 0;
1.52 +};
1.53 +
1.54 +// DMA device control.
1.55 +
1.56 +class Dma_chip
1.57 +{
1.58 +public:
1.59 + virtual void disable() = 0;
1.60 +
1.61 + virtual void enable() = 0;
1.62 +
1.63 + virtual Dma_channel *get_channel(uint8_t channel, l4_cap_idx_t irq) = 0;
1.64 +
1.65 + // Transaction control.
1.66 +
1.67 + virtual void ack_irq(uint8_t channel)
1.68 + {
1.69 + (void) channel;
1.70 + }
1.71 +
1.72 + virtual bool error()
1.73 + {
1.74 + return false;
1.75 + }
1.76 +
1.77 + virtual bool halted()
1.78 + {
1.79 + return false;
1.80 + }
1.81 +
1.82 + virtual void commit_descriptor(uint8_t channel)
1.83 + {
1.84 + (void) channel;
1.85 + }
1.86 +
1.87 + virtual bool have_interrupt(uint8_t channel) = 0;
1.88 +};
1.89 +
1.90 +// Generic access to the DMA abstraction.
1.91 +
1.92 +Dma_chip *new_dma_chip(const char *name, l4_addr_t start, l4_addr_t end, Cpm_chip *cpm);
1.93 +
1.94 +#endif /* __cplusplus */