struct fs_dma_channel
{
- int regmap;
qemu_irq *irq;
struct etraxfs_dma_client *client;
-
/* Internal status. */
int stream_cmd_src;
enum dma_ch_state state;
struct fs_dma_ctrl
{
+ int map;
CPUState *env;
- target_phys_addr_t base;
int nr_channels;
struct fs_dma_channel *channels;
&& ctrl->channels[c].client;
}
-static inline int fs_channel(target_phys_addr_t base, target_phys_addr_t addr)
+static inline int fs_channel(target_phys_addr_t addr)
{
/* Every channel has a 0x2000 ctrl register map. */
- return (addr - base) >> 13;
+ return addr >> 13;
}
#ifdef USE_THIS_DEAD_CODE
ctrl->channels[c].state = RUNNING;
} else
printf("WARNING: starting DMA ch %d with no client\n", c);
+
+ qemu_bh_schedule_idle(ctrl->bh);
}
static void channel_continue(struct fs_dma_ctrl *ctrl, int c)
qemu_irq_lower(ctrl->channels[c].irq[0]);
}
-static void channel_out_run(struct fs_dma_ctrl *ctrl, int c)
+static int channel_out_run(struct fs_dma_ctrl *ctrl, int c)
{
uint32_t len;
uint32_t saved_data_buf;
unsigned char buf[2 * 1024];
- while (ctrl->channels[c].eol != 1) {
+ if (ctrl->channels[c].eol)
+ return 0;
+
+ do {
saved_data_buf = channel_reg(ctrl, c, RW_SAVED_DATA_BUF);
D(printf("ch=%d buf=%x after=%x saved_data_buf=%x\n",
(uint32_t)ctrl->channels[c].current_d.after,
saved_data_buf));
- len = (uint32_t)ctrl->channels[c].current_d.after;
+ len = (uint32_t)(unsigned long)
+ ctrl->channels[c].current_d.after;
len -= saved_data_buf;
if (len > sizeof buf)
saved_data_buf += len;
- if (saved_data_buf ==
- (uint32_t)ctrl->channels[c].current_d.after) {
+ if (saved_data_buf == (uint32_t)(unsigned long)
+ ctrl->channels[c].current_d.after) {
/* Done. Step to next. */
if (ctrl->channels[c].current_d.out_eop) {
/* TODO: signal eop to the client. */
channel_stop(ctrl, c);
} else {
ctrl->channels[c].regs[RW_SAVED_DATA] =
- (uint32_t)ctrl->channels[c].current_d.next;
+ (uint32_t)(unsigned long)ctrl->
+ channels[c].current_d.next;
/* Load new descriptor. */
channel_load_d(ctrl, c);
saved_data_buf = (uint32_t)(unsigned long)
D(dump_d(c, &ctrl->channels[c].current_d));
}
ctrl->channels[c].regs[RW_SAVED_DATA_BUF] = saved_data_buf;
- }
+ } while (!ctrl->channels[c].eol);
+ return 1;
}
static int channel_in_process(struct fs_dma_ctrl *ctrl, int c,
return 0;
saved_data_buf = channel_reg(ctrl, c, RW_SAVED_DATA_BUF);
- len = (uint32_t)ctrl->channels[c].current_d.after;
+ len = (uint32_t)(unsigned long)ctrl->channels[c].current_d.after;
len -= saved_data_buf;
if (len > buflen)
saved_data_buf += len;
if (saved_data_buf ==
- (uint32_t)ctrl->channels[c].current_d.after
+ (uint32_t)(unsigned long)ctrl->channels[c].current_d.after
|| eop) {
uint32_t r_intr = ctrl->channels[c].regs[R_INTR];
channel_stop(ctrl, c);
} else {
ctrl->channels[c].regs[RW_SAVED_DATA] =
- (uint32_t)ctrl->channels[c].current_d.next;
+ (uint32_t)(unsigned long)ctrl->
+ channels[c].current_d.next;
/* Load new descriptor. */
channel_load_d(ctrl, c);
- saved_data_buf = (uint32_t)
+ saved_data_buf = (uint32_t)(unsigned long)
ctrl->channels[c].current_d.buf;
}
}
return len;
}
-static inline void channel_in_run(struct fs_dma_ctrl *ctrl, int c)
+static inline int channel_in_run(struct fs_dma_ctrl *ctrl, int c)
{
- if (ctrl->channels[c].client->client.pull)
+ if (ctrl->channels[c].client->client.pull) {
ctrl->channels[c].client->client.pull(
ctrl->channels[c].client->client.opaque);
+ return 1;
+ } else
+ return 0;
}
static uint32_t dma_rinvalid (void *opaque, target_phys_addr_t addr)
int c;
uint32_t r = 0;
- /* Make addr relative to this instances base. */
- c = fs_channel(ctrl->base, addr);
- addr &= 0x1fff;
+ /* Make addr relative to this channel and bounded to nr regs. */
+ c = fs_channel(addr);
+ addr &= 0xff;
switch (addr)
{
case RW_STAT:
struct fs_dma_ctrl *ctrl = opaque;
int c;
- /* Make addr relative to this instances base. */
- c = fs_channel(ctrl->base, addr);
- addr &= 0x1fff;
+ /* Make addr relative to this channel and bounded to nr regs. */
+ c = fs_channel(addr);
+ addr &= 0xff;
switch (addr)
{
case RW_DATA:
&dma_writel,
};
-void etraxfs_dmac_run(void *opaque)
+static int etraxfs_dmac_run(void *opaque)
{
struct fs_dma_ctrl *ctrl = opaque;
int i;
{
if (ctrl->channels[i].state == RUNNING)
{
- p++;
- if (ctrl->channels[i].input)
- channel_in_run(ctrl, i);
- else
- channel_out_run(ctrl, i);
+ if (ctrl->channels[i].input) {
+ p += channel_in_run(ctrl, i);
+ } else {
+ p += channel_out_run(ctrl, i);
+ }
}
}
+ return p;
}
int etraxfs_dmac_input(struct etraxfs_dma_client *client,
static void DMA_run(void *opaque)
{
struct fs_dma_ctrl *etraxfs_dmac = opaque;
+ int p = 1;
+
if (vm_running)
- etraxfs_dmac_run(etraxfs_dmac);
- qemu_bh_schedule_idle(etraxfs_dmac->bh);
+ p = etraxfs_dmac_run(etraxfs_dmac);
+
+ if (p)
+ qemu_bh_schedule_idle(etraxfs_dmac->bh);
}
void *etraxfs_dmac_init(CPUState *env,
target_phys_addr_t base, int nr_channels)
{
struct fs_dma_ctrl *ctrl = NULL;
- int i;
ctrl = qemu_mallocz(sizeof *ctrl);
if (!ctrl)
return NULL;
ctrl->bh = qemu_bh_new(DMA_run, ctrl);
- qemu_bh_schedule_idle(ctrl->bh);
- ctrl->base = base;
ctrl->env = env;
ctrl->nr_channels = nr_channels;
ctrl->channels = qemu_mallocz(sizeof ctrl->channels[0] * nr_channels);
if (!ctrl->channels)
goto err;
- for (i = 0; i < nr_channels; i++)
- {
- ctrl->channels[i].regmap = cpu_register_io_memory(0,
- dma_read,
- dma_write,
- ctrl);
- cpu_register_physical_memory (base + i * 0x2000,
- sizeof ctrl->channels[i].regs,
- ctrl->channels[i].regmap);
- }
-
+ ctrl->map = cpu_register_io_memory(0, dma_read, dma_write, ctrl);
+ cpu_register_physical_memory(base, nr_channels * 0x2000, ctrl->map);
return ctrl;
err:
qemu_free(ctrl->channels);