DevDMA.cpp revision c98fb3e16fcd571a790eab772c0c66173d225205
/* $Id$ */
/** @file
* DMA Controller Device.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
* --------------------------------------------------------------------
*
* This code is based on:
*
* QEMU DMA emulation
*
* Copyright (c) 2003 Vassili Karpov (malc)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifdef VBOX
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "Builtins.h"
#include "../vl_vbox.h"
#else /* !VBOX */
#include "vl.h"
#endif
/* #define DEBUG_DMA */
#ifndef VBOX
#ifndef __WIN32__
#ifdef DEBUG_DMA
#else
#define lwarn(...)
#define linfo(...)
#define ldebug(...)
#endif
#else
#define dolog()
#define lwarn()
#define linfo()
#define ldebug()
#endif
#else /* VBOX */
#ifdef LOG_ENABLED
#endif
# ifdef LOG_ENABLED
# define DEBUG_DMA
static void DMA_DPRINTF (const char *fmt, ...)
{
if (LogIsEnabled ()) {
}
}
# else
# endif
#define dolog DMA_DPRINTF
#define lwarn DMA_DPRINTF
#define linfo DMA_DPRINTF
#define ldebug DMA_DPRINTF
#endif /* VBOX */
#define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0])))
struct dma_regs {
unsigned int now[2];
void *opaque;
};
#define ADDR 0
#define COUNT 1
struct dma_cont {
unsigned int dshift;
};
typedef struct {
} DMAState;
enum {
CMD_MEMORY_TO_MEMORY = 0x01,
CMD_FIXED_ADDRESS = 0x02,
CMD_BLOCK_CONTROLLER = 0x04,
CMD_COMPRESSED_TIME = 0x08,
CMD_CYCLIC_PRIORITY = 0x10,
CMD_EXTENDED_WRITE = 0x20,
CMD_LOW_DREQ = 0x40,
CMD_LOW_DACK = 0x80,
};
{
int ichan;
if (-1 == ichan) {
return;
}
}
{
int ichan;
if (-1 == ichan) {
return;
}
}
{
int ichan;
if (-1 == ichan) {
return 0;
}
}
{
int ichan;
if (-1 == ichan) {
return 0;
}
}
{
struct dma_regs *r;
}
{
int ff;
return ff;
}
{
struct dma_regs *r;
if (nreg)
else
}
{
struct dma_regs *r;
if (getff (d)) {
} else {
}
}
{
switch (iport) {
case 0x08: /* command */
return;
}
break;
case 0x09:
if (data & 4) {
}
else {
}
break;
case 0x0a: /* single mask */
if (data & 4)
else
break;
case 0x0b: /* mode */
{
#ifdef DEBUG_DMA
{
linfo ("ichan %d, op %d, ai %d, dir %d, opmode %d\n",
}
#endif
break;
}
case 0x0c: /* clear flip flop */
d->flip_flop = 0;
break;
case 0x0d: /* reset */
d->flip_flop = 0;
d->mask = ~0;
d->status = 0;
d->command = 0;
break;
case 0x0e: /* clear mask for all channels */
d->mask = 0;
break;
case 0x0f: /* write mask for all channels */
break;
default:
break;
}
#ifdef DEBUG_DMA
if (0xc != iport) {
linfo ("write_cont: nport %#06x, ichan % 2d, val %#06x\n",
}
#endif
}
{
switch (iport) {
case 0x08: /* status */
d->status &= 0xf0;
break;
case 0x0f: /* mask */
break;
default:
val = 0;
break;
}
return val;
}
{
}
{
}
{
}
{
int n;
#ifdef DEBUG_DMA
if (dir) {
dolog ("DMA in address decrement mode\n");
}
if (opmode != 1) {
}
#endif
}
{
struct dma_cont *d;
d = s->dma_controllers;
int mask;
}
}
}
void *opaque)
{
struct dma_regs *r;
LogFlow (("DMA_register_channel: s=%p nchan=%d transfer_handler=%p opaque=%p\n",
}
unsigned nchan,
void *buf,
{
if (r->mode & 0x20) {
unsigned i;
#ifdef VBOX
#else
#endif
/* What about 16bit transfers? */
for (i = 0; i < len >> 1; i++) {
p[i] = b;
}
}
else
#ifdef VBOX
#else
#endif
return len;
}
unsigned nchan,
const void *buf,
{
if (r->mode & 0x20) {
unsigned i;
#ifdef VBOX
#else
#endif
/* What about 16bit transfers? */
for (i = 0; i < len; i++) {
p[i] = b;
}
}
else
#ifdef VBOX
#else
#endif
return len;
}
#ifndef VBOX
/* request the emulator to transfer a new DMA memory block ASAP */
void DMA_schedule(int nchan)
{
}
#endif
{
}
#ifdef VBOX
#define IO_READ_PROTO(n) \
void *pvUser, \
unsigned cb)
#define IO_WRITE_PROTO(n) \
void *pvUser, \
unsigned cb)
{
if (cb == 1) {
}
#ifdef PARANOID
else {
Log (("Unknown write to %#x of size %d, value %#x\n",
}
#endif
return VINF_SUCCESS;
}
{
if (cb == 1) {
}
#ifdef PARANOID
else {
Log (("Unknown write to %#x of size %d, value %#x\n",
}
#endif
return VINF_SUCCESS;
}
{
if (cb == 1) {
}
#ifdef PARANOID
else {
Log (("Unknown write to %#x of size %d, value %#x\n",
}
#endif
return VINF_SUCCESS;
}
{
if (cb == 1) {
}
#ifdef PARANOID
else {
Log (("Unknown write to %#x of size %d, value %#x\n",
}
#endif
return VINF_SUCCESS;
}
{
if (cb == 1) {
return VINF_SUCCESS;
}
else {
return VERR_IOM_IOPORT_UNUSED;
}
}
{
if (cb == 1) {
return VINF_SUCCESS;
}
else {
return VERR_IOM_IOPORT_UNUSED;
}
}
{
if (cb == 1) {
return VINF_SUCCESS;
}
else {
return VERR_IOM_IOPORT_UNUSED;
}
}
{
if (cb == 1) {
return VINF_SUCCESS;
}
else {
return VERR_IOM_IOPORT_UNUSED;
}
}
#endif
/* dshift = 0: 8 bit DMA, 1 = 16 bit DMA */
int page_base, int pageh_base)
{
int i;
for (i = 0; i < 8; i++) {
#ifdef VBOX
#else
#endif
}
for (i = 0; i < LENOFA (page_port_list); i++) {
#ifdef VBOX
#else
write_page, d);
read_page, d);
#endif
if (pageh_base >= 0) {
#ifdef VBOX
#else
write_pageh, d);
read_pageh, d);
#endif
}
}
for (i = 0; i < 8; i++) {
#ifdef VBOX
#else
write_cont, d);
read_cont, d);
#endif
}
#ifndef VBOX
#endif
dma_reset(d);
}
{
int i;
/* qemu_put_8s (f, &d->status); */
qemu_put_8s (f, &d->command);
qemu_put_8s (f, &d->mask);
qemu_put_8s (f, &d->flip_flop);
qemu_put_be32s (f, &d->dshift);
for (i = 0; i < 4; ++i) {
qemu_put_be32s (f, &r->now[0]);
qemu_put_be16s (f, &r->base[0]);
qemu_put_8s (f, &r->mode);
qemu_put_8s (f, &r->page);
qemu_put_8s (f, &r->pageh);
qemu_put_8s (f, &r->dack);
qemu_put_8s (f, &r->eop);
}
}
{
int i;
if (version_id != 1)
#ifdef VBOX
#else
return -EINVAL;
#endif
/* qemu_get_8s (f, &d->status); */
qemu_get_8s (f, &d->command);
qemu_get_8s (f, &d->mask);
qemu_get_8s (f, &d->flip_flop);
qemu_get_be32s (f, &d->dshift);
for (i = 0; i < 4; ++i) {
qemu_get_be32s (f, &r->now[0]);
qemu_get_be16s (f, &r->base[0]);
qemu_get_8s (f, &r->mode);
qemu_get_8s (f, &r->page);
qemu_get_8s (f, &r->pageh);
qemu_get_8s (f, &r->dack);
qemu_get_8s (f, &r->eop);
}
return 0;
}
#ifndef VBOX
void DMA_init (int high_page_enable)
{
}
#endif
#ifdef VBOX
{
return 0;
}
unsigned nchan,
void *opaque)
{
}
unsigned nchan,
void *buf,
{
}
unsigned nchan,
const void *buf,
{
}
unsigned nchan,
unsigned level)
{
if (level) {
DMA_hold_DREQ (s, nchan);
}
else {
DMA_release_DREQ (s, nchan);
}
}
{
return DMA_get_channel_mode (s, nchan);
}
{
dma_reset (&s->dma_controllers[0]);
}
{
return VINF_SUCCESS;
}
{
if (u32Version != 1) {
AssertFailed ();
}
}
/**
* Construct a device instance for a VM.
*
* @returns VBox status.
* @param pDevIns The device instance data.
* If the registration structure is needed, pDevIns->pDevReg points to it.
* @param iInstance Instance number. Use this to figure out which registers and such to use.
* The device number is also found in pDevIns->iInstance, but since it's
* likely to be freqently used PDM passes it as parameter.
* @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
* of the device instance. It's also found in pDevIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
int iInstance,
{
bool high_page_enable = 0;
int rc;
/*
* Validate configuration.
*/
#if 0
if (VBOX_FAILURE (rc)) {
return rc;
}
#endif
if (VBOX_FAILURE (rc)) {
return rc;
}
if (VBOX_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/**
* The device registration structure.
*/
const PDMDEVREG g_DeviceDMA =
{
/* u32Version */
/* szDeviceName */
"8237A",
/* szGCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"DMA Controller Device",
/* fFlags */
/* fClass */
/* cMaxInstances */
1,
/* cbInstance */
sizeof(DMAState),
/* pfnConstruct */
/* pfnDestruct */
NULL,
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface. */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
};
#endif /* VBOX */