Call finish funcs for devices when closing bus.

This commit is contained in:
Radosław Kujawa 2018-07-24 11:02:22 +02:00
parent ef69c47c25
commit 61cc5d2c68
No known key found for this signature in database
GPG Key ID: 18A71CD0FD7270D7
4 changed files with 16 additions and 7 deletions

View File

@ -195,6 +195,15 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename)
void
bus_finish(bus_t *t)
{
device_mapping_t *dm;
device_t *d;
assert(t != NULL);
LL_FOREACH(t->dm_head, dm) {
d = dm->dev;
if ((d->finish) != NULL)
d->finish(d);
}
}

View File

@ -8,6 +8,7 @@ typedef struct device_t {
uint8_t (*read_1)(void *, uint16_t doff);
void (*write_1)(void *, uint16_t, uint8_t val);
void (*finish)(void *);
void *config;
void *aux; /* any dev space-specific data */

View File

@ -49,6 +49,7 @@ device_ram_init(uint16_t size)
d->read_1 = device_ram_read_1;
d->write_1 = device_ram_write_1;
d->finish = NULL;
d->aux = GC_MALLOC(size);
memset(d->aux, 0, size);
@ -56,8 +57,4 @@ device_ram_init(uint16_t size)
return d;
}
void
device_ram_finish(device_t *d)
{
}

View File

@ -22,6 +22,7 @@ struct device_serial_priv {
uint8_t device_serial_read_1(void *, uint16_t);
void device_serial_write_1(void *, uint16_t, uint8_t);
void device_serial_finish(void *);
uint8_t
device_serial_read_1(void *vd, uint16_t offset)
@ -85,6 +86,7 @@ device_serial_init()
d->read_1 = device_serial_read_1;
d->write_1 = device_serial_write_1;
d->finish = device_serial_finish;
dp = (struct device_serial_priv *) GC_MALLOC(sizeof(struct device_serial_priv));
d->aux = dp;
@ -105,10 +107,12 @@ device_serial_init()
}
void
device_serial_finish(device_t *d)
device_serial_finish(void *dv)
{
struct device_serial_priv *dp;
struct device_t *d;
d = (struct device_t *) dv;
dp = d->aux;
close(dp->txpipefd);
@ -116,7 +120,5 @@ device_serial_finish(device_t *d)
unlink(txpipepath);
unlink(rxpipepath);
// XXX?
}