1/1

|
[or1ksim #19] Clean up ata peripheral
by Unknown on Feb 4, 2005 |
Not available! | ||
|
Hi,
This cleans up the ata peripheral to make use of the new callbacks.
ChangeLog:
* Clean up the ata peripheral useing the new set of callbacks.
nog.
-------------- next part --------------
--- peripheral/atahost.c 2005-02-04 11:15:31.000000000 +0100
+++ ../or1ksim-ac/peripheral/atahost.c 2005-02-03 21:42:23.000000000 +0100
@@ -19,6 +19,8 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include
+
#include "config.h"
#ifdef HAVE_INTTYPES_H
@@ -37,86 +39,26 @@
#include "atahost.h"
#include "messages.h"
-static ata_host atas[MAX_ATAS];
-
/* reset and initialize ATA host core(s) */
-void ata_reset(void)
+void ata_reset(void *dat)
{
- static int first_time=0;
-
- unsigned i;
- ata_host *ata;
-
- // for all ATA cores
- for (i=0; i regs.ctrl = 0x0001;
- ata->regs.stat = (DEV_ID regs.pctr = (PIO_MODE0_TEOC regs.pftr0 = (PIO_MODE0_TEOC regs.pftr1 = (PIO_MODE0_TEOC regs.dtr0 = (DMA_MODE0_TEOC regs.dtr1 = (DMA_MODE0_TEOC regs.txb = 0;
-
- // copy the config settings
- ata->ata_number = i;
- ata->irq = config.atas.irq;
- ata->baseaddr = config.atas.baseaddr;
-
- ata->devices.device0.size = config.atas.dev_size0;
- ata->devices.device0.type = config.atas.dev_type0;
- ata->devices.device0.packet = config.atas.dev_packet0;
- ata->devices.device1.size = config.atas.dev_size1;
- ata->devices.device1.type = config.atas.dev_type1;
- ata->devices.device1.packet = config.atas.dev_packet1;
-
- // inform simulator about new read/write delay timings
- adjust_rw_delay( ata->baseaddr, ata_pio_delay(ata->regs.pctr), ata_pio_delay(ata->regs.pctr) );
-
- /* initialize simulator & ata_devices */
- if (!first_time)
- {
- /* Connect ata_devices. */
- ata_devices_init(&ata->devices, config.atas.dev_file0, config.atas.dev_file1);
+ ata_host *ata = dat;
- register_memoryarea(ata->baseaddr, ATA_ADDR_SPACE, 4, 0, ata_read32, ata_write32, NULL);
- }
+ // reset the core registers
+ ata->regs.ctrl = 0x0001;
+ ata->regs.stat = (DEV_ID regs.pctr = (PIO_MODE0_TEOC regs.pftr0 = (PIO_MODE0_TEOC regs.pftr1 = (PIO_MODE0_TEOC regs.dtr0 = (DMA_MODE0_TEOC regs.dtr1 = (DMA_MODE0_TEOC regs.txb = 0;
- /* the reset bit in the control register 'ctrl' is set, reset connect ata-devices */
- ata_devices_hw_reset(&ata->devices, 1);
- }
+ // inform simulator about new read/write delay timings
+ adjust_rw_delay( ata->baseaddr, ata_pio_delay(ata->regs.pctr), ata_pio_delay(ata->regs.pctr) );
- first_time++;
-}
-/* ========================================================================= */
-
-
-/* Convert a memory address to a device struct and relative address.
- * Return nonzero on success */
-int ata_find_device( oraddr_t addr, ata_host **ata, oraddr_t *reladdr )
-{
- unsigned i;
- *ata = NULL;
-
- for ( i = 0; i = atas.baseaddr) && (addr baseaddr) % 4 != 0 )
- return 0;
-
- *reladdr = addr - (*ata) -> baseaddr;
- return 1;
+ /* the reset bit in the control register 'ctrl' is set, reset connect ata-devices */
+ ata_devices_hw_reset(&ata->devices, 1);
}
/* ========================================================================= */
@@ -126,12 +68,9 @@
*/
uint32_t ata_read32( oraddr_t addr, void *dat )
{
- ata_host *ata;
+ ata_host *ata = dat;
- if ( !ata_find_device( addr, &ata, &addr ) ) {
- fprintf(stderr, "ata_read32( 0x%"PRIxADDR" ): Not in registered range(s)\n", addr );
- return 0;
- }
+ addr -= ata->baseaddr;
/* determine if ata_host or ata_device addressed */
if (is_ata_hostadr(addr))
@@ -200,13 +139,9 @@
*/
void ata_write32( oraddr_t addr, uint32_t value, void *dat )
{
- ata_host *ata;
+ ata_host *ata = dat;
- if ( !ata_find_device( addr, &ata, &addr ) )
- {
- fprintf(stderr, "ata_write32( 0x%"PRIxADDR" ): Not in registered range(s)\n", addr );
- return;
- }
+ addr -= ata->baseaddr;
/* determine if ata_host or ata_device addressed */
if (is_ata_hostadr(addr))
@@ -289,132 +224,129 @@
/* Dump status */
-void ata_status( void )
+void ata_status( void *dat )
{
- unsigned i;
- ata_host *ata;
+ ata_host *ata = dat;
- for ( i = 0; i baseaddr == 0 )
+ return;
- if ( ata->baseaddr == 0 )
- continue;
-
- PRINTF( "\nOCIDEC-%1d %u at: 0x%"PRIxADDR"\n", DEV_ID, i, ata->baseaddr );
- PRINTF( "ATA CTRL : 0x%08X\n", ata->regs.ctrl );
- PRINTF( "ATA STAT : 0x%08x\n", ata->regs.stat );
- PRINTF( "ATA PCTR : 0x%08x\n", ata->regs.pctr );
+ PRINTF( "\nOCIDEC-%1d at: 0x%"PRIxADDR"\n", DEV_ID, ata->baseaddr );
+ PRINTF( "ATA CTRL : 0x%08X\n", ata->regs.ctrl );
+ PRINTF( "ATA STAT : 0x%08x\n", ata->regs.stat );
+ PRINTF( "ATA PCTR : 0x%08x\n", ata->regs.pctr );
#if (DEV_ID > 1)
- PRINTF( "ATA FCTR0 : 0x%08lx\n", ata->regs.pftr0 );
- PRINTF( "ATA FCTR1 : 0x%08lx\n", ata->regs.pftr1 );
+ PRINTF( "ATA FCTR0 : 0x%08lx\n", ata->regs.pftr0 );
+ PRINTF( "ATA FCTR1 : 0x%08lx\n", ata->regs.pftr1 );
#endif
#if (DEV_ID > 2)
- PRINTF( "ATA DTR0 : 0x%08lx\n", ata->regs.dtr0 );
- PRINTF( "ATA DTR1 : 0x%08lx\n", ata->regs.dtr1 );
- PRINTF( "ATA TXD : 0x%08lx\n", ata->regs.txb );
- PRINTF( "ATA RXD : 0x%08lx\n", ata->regs.rxb );
+ PRINTF( "ATA DTR0 : 0x%08lx\n", ata->regs.dtr0 );
+ PRINTF( "ATA DTR1 : 0x%08lx\n", ata->regs.dtr1 );
+ PRINTF( "ATA TXD : 0x%08lx\n", ata->regs.txb );
+ PRINTF( "ATA RXD : 0x%08lx\n", ata->regs.rxb );
#endif
- }
}
/* ========================================================================= */
/*----------------------------------------------------[ ATA Configuration ]---*/
-void ata_natas(union param_val val, void *dat)
-{
- if (val.int_val >= 0 && val.int_val = 0 && current_device baseaddr = val.addr_val;
}
void ata_irq(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device irq = val.int_val;
}
void ata_dev_type0(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device0.type = val.int_val;
}
void ata_dev_file0(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device0.file = strdup(val.str_val))) {
+ fprintf(stderr, "Peripheral ATA: Run out of memory\n");
+ exit(-1);
+ }
}
void ata_dev_size0(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device0.size = val.int_val;
}
void ata_dev_packet0(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device0.packet = val.int_val;
}
void ata_dev_type1(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device1.packet = val.int_val;
}
void ata_dev_file1(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device1.file = strdup(val.str_val))) {
+ fprintf(stderr, "Peripheral ATA: Run out of memory\n");
+ exit(-1);
+ }
}
void ata_dev_size1(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device1.size = val.int_val;
}
void ata_dev_packet1(union param_val val, void *dat)
{
- if (current_device >= 0 && current_device devices.device1.packet = val.int_val;
+}
+
+void *ata_sec_start(void)
+{
+ ata_host *new = malloc(sizeof(ata_host));
+
+ if(!new) {
+ fprintf(stderr, "Peripheral ATA: Run out of memory\n");
+ exit(-1);
+ }
+
+ memset(new, 0, sizeof(ata_host));
+ return new;
+}
+
+void ata_sec_end(void *dat)
+{
+ ata_host *ata = dat;
+
+ /* Connect ata_devices. */
+ ata_devices_init(&ata->devices);
+
+ register_memoryarea(ata->baseaddr, ATA_ADDR_SPACE, 4, 0, ata_read32, ata_write32, dat);
+
+ reg_sim_reset(ata_reset, dat);
+ reg_sim_stat(ata_status, dat);
}
void reg_ata_sec(void)
{
- struct config_section *sec = reg_config_sec("ata", NULL, NULL);
+ struct config_section *sec = reg_config_sec("ata", ata_sec_start, ata_sec_end);
- reg_config_param(sec, "natas", paramt_int, ata_natas);
- reg_config_param(sec, "device", paramt_int, change_device);
reg_config_param(sec, "baseaddr", paramt_addr, ata_baseaddr);
reg_config_param(sec, "irq", paramt_int, ata_irq);
reg_config_param(sec, "dev_type0", paramt_int, ata_dev_type0);
@@ -425,5 +357,4 @@
reg_config_param(sec, "dev_file1", paramt_str, ata_dev_file1);
reg_config_param(sec, "dev_size1", paramt_int, ata_dev_size1);
reg_config_param(sec, "dev_packet1", paramt_int, ata_dev_packet1);
- reg_config_param(sec, "enddevice", paramt_none, end_device);
}
--- peripheral/atahost.h 2005-02-04 11:15:31.000000000 +0100
+++ ../or1ksim-ac/peripheral/atahost.h 2005-02-03 21:17:40.000000000 +0100
@@ -108,9 +108,6 @@
/* Which IRQ to generate */
int irq;
- /* Which ATA host is this? */
- unsigned ata_number;
-
/* ata host registers */
struct {
int ctrl;
@@ -131,10 +128,10 @@
/* ---------------------------- */
/* ----- Prototypes ----- */
/* ---------------------------- */
-void ata_reset(void);
+void ata_reset(void *dat);
uint32_t ata_read32( oraddr_t addr, void *dat );
void ata_write32( oraddr_t addr, uint32_t value, void *dat );
-void ata_status(void);
+void ata_status(void *dat);
/* ---------------------------- */
--- peripheral/atadevice.c 2005-02-04 11:15:22.000000000 +0100
+++ ../or1ksim-ac/peripheral/atadevice.c 2005-02-03 21:17:04.000000000 +0100
@@ -73,18 +73,18 @@
/*
D E V I C E S _ I N I T
*/
-void ata_devices_init(ata_devices *devices, const char *filename0, const char *filename1)
+void ata_devices_init(ata_devices *devices)
{
- ata_device_init(&devices->device0, 0, filename0);
+ ata_device_init(&devices->device0, 0);
if (devices->device0.type)
- ata_device_init(&devices->device1, ATA_DHR_DEV, filename1);
+ ata_device_init(&devices->device1, ATA_DHR_DEV);
else
- ata_device_init(&devices->device1, 0, filename1);
+ ata_device_init(&devices->device1, 0);
}
-void ata_device_init(ata_device *device, int dev, const char *filename)
+void ata_device_init(ata_device *device, int dev)
{
/* set DeviceID */
device->internals.dev = dev;
@@ -99,7 +99,7 @@
case TYPE_FILE:
MSG_NOTE("ata_device, using device type FILE.");
- device->stream = open_file(&device->size, filename);
+ device->stream = open_file(&device->size, device->file);
break;
case TYPE_LOCAL:
--- peripheral/atadevice.h 2002-12-03 12:42:20.000000000 +0100
+++ ../or1ksim-ac/peripheral/atadevice.h 2005-02-03 21:05:28.000000000 +0100
@@ -174,6 +174,7 @@
/******** simulator settings **********************************/
/* simulate ata-device */
+ char *file; /* Filename (if type == FILE) */
FILE *stream; /* stream where the simulated device connects to*/
int type; /* Simulate device using */
/* NO_CONNECT: no device connected (dummy) */
@@ -194,13 +195,13 @@
int ata_device_debug(int lvl, char *format, ...);
/* all devices */
-void ata_devices_init(ata_devices *devices, const char *filename0, const char *filename1);
+void ata_devices_init(ata_devices *devices);
void ata_devices_hw_reset(ata_devices *devices, int reset_signal);
short ata_devices_read(ata_devices *devices, char adr);
void ata_devices_write(ata_devices *devices, char adr, short value);
/* single device */
-void ata_device_init(ata_device *device, int dev, const char *filename);
+void ata_device_init(ata_device *device, int dev);
void ata_device_hw_reset(ata_device *device, int reset_signal, int daspo, int pdiagi, int daspi);
void ata_device_do_control_register(ata_device *device);
void ata_device_do_command_register(ata_device *device);
--- sim-config.h 2005-02-04 11:15:36.000000000 +0100
+++ ../or1ksim-ac/sim-config.h 2005-02-04 11:07:40.000000000 +0100
@@ -110,22 +110,6 @@
unsigned POC; /* power on reset configuration register */
} mc;
- int natas;
- struct {
- unsigned long baseaddr; /* Naturally aligned base address */
- int irq; /* Irq number of this device */
-
- int dev_type0; /* ATA-device0 type: 0=none, 1=simulated hd, 2=local system hd */
- char dev_file0[STR_SIZE]; /* Filename for simulating HardDisk (device 0) */
- unsigned long dev_size0; /* Size of simulated harddisk (device 0), in MBytes */
- int dev_packet0; /* Device0 implements PACKET command set */
-
- int dev_type1; /* ATA-device1 type: 0=none, 1=simulated hd, 2=local system hd */
- char dev_file1[STR_SIZE]; /* Filename for simulating HardDisk (device 1) */
- unsigned long dev_size1; /* Size of simulated harddisk (device 1), in MBytes */
- int dev_packet1; /* Device1 implements PACKET command set */
- } atas[MAX_ATAS];
-
struct {
int pattern; /* A user specified memory initialization pattern */
int random_seed; /* Initialize the memory with random values, starting with seed */
--- toplevel.c 2005-02-04 11:15:33.000000000 +0100
+++ ../or1ksim-ac/toplevel.c 2005-02-03 21:20:07.000000000 +0100
@@ -59,7 +59,6 @@
#include "profiler.h"
#include "mprofiler.h"
#include "mc.h"
-#include "atahost.h"
#include "16450.h"
#include "ethernet.h"
#include "gpio.h"
@@ -180,7 +179,6 @@
vga_reset ();
fb_reset ();
kbd_reset ();
- ata_reset();
tick_reset();
pm_reset();
pic_reset();
--- sim-cmd.c 2005-02-04 11:25:36.000000000 +0100
+++ ../or1ksim-ac/sim-cmd.c 2005-02-04 11:23:39.000000000 +0100
@@ -64,7 +64,6 @@
#include "dma.h"
#include "ethernet.h"
#include "gpio.h"
-#include "atahost.h"
#include "ps2kbd.h"
struct sim_stat {
@@ -429,7 +438,6 @@
if (config.ndmas) dma_status();
if (config.nethernets) eth_status();
if (config.ngpios) gpio_status();
- if (config.natas) ata_status();
kbd_info();
while(cur_stat) {
--- sim.cfg 2003-03-28 00:22:53.000000000 +0100
+++ ../or1ksim-ac/sim.cfg 2005-02-04 11:32:04.000000000 +0100
@@ -870,10 +870,6 @@
This section configures the ATA/ATAPI host controller
- natas =
- number of ATA hosts connected
-
- instance specific:
baseaddr =
address of first ATA register
@@ -911,22 +907,18 @@
*/
section ata
- natas = 1
+ baseaddr = 0x9e000000
+ irq = 15
- device 0
- baseaddr = 0x9e000000
- irq = 15
-
- dev_type0 = 1
- dev_file0 = "/tmp/sim_atadev0"
- dev_size0 = 1
- dev_packet0 = 0
-
- dev_type1 = 0
- dev_file1 = ""
- dev_size1 = 0
- dev_packet1 = 0
- enddevice
+ dev_type0 = 1
+ dev_file0 = "/tmp/sim_atadev0"
+ dev_size0 = 1
+ dev_packet0 = 0
+
+ dev_type1 = 0
+ dev_file1 = ""
+ dev_size1 = 0
+ dev_packet1 = 0
end
|
|||
1/1

