2020-03-18 16:34:03 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2022-10-20 11:20:06 +00:00
|
|
|
Copyright (C) 2018-22 divingkatae and maximum
|
2020-03-18 16:34:03 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Descriptor-based direct memory access emulation.
|
|
|
|
|
|
|
|
Official documentation can be found in the fifth chapter of the book
|
|
|
|
"Macintosh Technology in the Common Hardware Reference Platform"
|
|
|
|
by Apple Computer, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DB_DMA_H
|
|
|
|
#define DB_DMA_H
|
|
|
|
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/common/dmacore.h>
|
|
|
|
|
2020-03-18 16:34:03 +00:00
|
|
|
#include <cinttypes>
|
2021-10-04 22:26:43 +00:00
|
|
|
#include <functional>
|
2020-03-18 16:34:03 +00:00
|
|
|
|
|
|
|
/** DBDMA Channel registers offsets */
|
|
|
|
enum DMAReg : uint32_t {
|
2020-05-12 18:55:45 +00:00
|
|
|
CH_CTRL = 0,
|
|
|
|
CH_STAT = 4,
|
|
|
|
CMD_PTR_LO = 12,
|
2020-03-18 16:34:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
2022-10-20 11:20:06 +00:00
|
|
|
enum : uint16_t {
|
2020-05-12 18:55:45 +00:00
|
|
|
CH_STAT_ACTIVE = 0x400,
|
|
|
|
CH_STAT_DEAD = 0x800,
|
|
|
|
CH_STAT_WAKE = 0x1000,
|
|
|
|
CH_STAT_FLUSH = 0x2000,
|
|
|
|
CH_STAT_PAUSE = 0x4000,
|
|
|
|
CH_STAT_RUN = 0x8000
|
2020-03-18 16:34:03 +00:00
|
|
|
};
|
|
|
|
|
2020-03-19 01:00:18 +00:00
|
|
|
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
|
|
|
|
typedef struct DMACmd {
|
2022-10-20 11:20:06 +00:00
|
|
|
uint16_t req_count;
|
|
|
|
uint8_t cmd_bits;
|
|
|
|
uint8_t cmd_key;
|
|
|
|
uint32_t address;
|
|
|
|
uint32_t cmd_arg;
|
|
|
|
uint16_t res_count;
|
|
|
|
uint16_t xfer_stat;
|
2020-03-19 01:00:18 +00:00
|
|
|
} DMACmd;
|
|
|
|
|
2021-10-04 22:26:43 +00:00
|
|
|
typedef std::function<void(void)> DbdmaCallback;
|
2020-03-19 14:09:24 +00:00
|
|
|
|
2022-10-20 11:20:06 +00:00
|
|
|
class DMAChannel : public DmaBidirChannel {
|
2020-03-18 16:34:03 +00:00
|
|
|
public:
|
2021-10-04 22:26:43 +00:00
|
|
|
DMAChannel() = default;
|
2020-03-18 16:34:03 +00:00
|
|
|
~DMAChannel() = default;
|
|
|
|
|
2021-10-04 22:26:43 +00:00
|
|
|
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
2020-03-18 16:34:03 +00:00
|
|
|
uint32_t reg_read(uint32_t offset, int size);
|
|
|
|
void reg_write(uint32_t offset, uint32_t value, int size);
|
|
|
|
|
2021-10-04 21:46:19 +00:00
|
|
|
bool is_active();
|
|
|
|
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
2022-10-20 11:20:06 +00:00
|
|
|
int push_data(const char* src_ptr, int len);
|
2020-03-26 01:07:12 +00:00
|
|
|
|
2020-03-18 16:34:03 +00:00
|
|
|
protected:
|
2022-10-20 11:20:06 +00:00
|
|
|
void fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
2020-03-19 01:00:18 +00:00
|
|
|
uint8_t interpret_cmd(void);
|
|
|
|
|
2020-03-18 16:34:03 +00:00
|
|
|
void start(void);
|
|
|
|
void resume(void);
|
|
|
|
void abort(void);
|
|
|
|
void pause(void);
|
|
|
|
|
|
|
|
private:
|
2022-10-20 11:20:06 +00:00
|
|
|
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
|
|
|
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
2021-10-04 22:26:43 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint16_t ch_stat = 0;
|
|
|
|
uint32_t cmd_ptr = 0;
|
2022-10-20 11:20:06 +00:00
|
|
|
uint32_t queue_len = 0;
|
|
|
|
uint8_t* queue_data = 0;
|
2020-03-26 01:07:12 +00:00
|
|
|
|
2022-10-20 11:20:06 +00:00
|
|
|
bool cmd_in_progress = false;
|
2020-03-18 16:34:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* DB_DMA_H */
|