Merge pull request #4688 from 86Box/tc1995

AMD/DC390 SCSI fixes of the day (August 4th, 2024)
This commit is contained in:
Miran Grča
2024-08-04 23:01:35 +02:00
committed by GitHub
6 changed files with 983 additions and 511 deletions

View File

@@ -21,14 +21,19 @@
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/fifo8.h> #include <86box/fifo8.h>
void
fifo8_reset(Fifo8 *fifo)
{
fifo->num = 0;
fifo->head = 0;
}
void void
fifo8_create(Fifo8 *fifo, uint32_t capacity) fifo8_create(Fifo8 *fifo, uint32_t capacity)
{ {
fifo->data = (uint8_t *) malloc(capacity); fifo->data = (uint8_t *) calloc(1, capacity);
memset(fifo->data, 0, capacity);
fifo->capacity = capacity; fifo->capacity = capacity;
fifo->head = 0; fifo8_reset(fifo);
fifo->num = 0;
} }
void void
@@ -54,7 +59,7 @@ fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
uint32_t start; uint32_t start;
uint32_t avail; uint32_t avail;
assert(fifo->num + num <= fifo->capacity); assert((fifo->num + num) <= fifo->capacity);
start = (fifo->head + fifo->num) % fifo->capacity; start = (fifo->head + fifo->num) % fifo->capacity;
@@ -81,25 +86,72 @@ fifo8_pop(Fifo8 *fifo)
return ret; return ret;
} }
const uint8_t * static const uint8_t
fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) *fifo8_peekpop_buf(Fifo8 *fifo, uint32_t max, uint32_t *numptr, int do_pop)
{ {
const uint8_t *ret; uint8_t *ret;
uint32_t num;
assert((max > 0) && (max <= fifo->num));
num = MIN(fifo->capacity - fifo->head, max);
ret = &fifo->data[fifo->head];
if (do_pop) {
fifo->head += num;
fifo->head %= fifo->capacity;
fifo->num -= num;
}
if (numptr)
*numptr = num;
assert(max > 0 && max <= fifo->num);
*num = MIN(fifo->capacity - fifo->head, max);
ret = &fifo->data[fifo->head];
fifo->head += *num;
fifo->head %= fifo->capacity;
fifo->num -= *num;
return ret; return ret;
} }
void const uint8_t
fifo8_reset(Fifo8 *fifo) *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{ {
fifo->num = 0; return fifo8_peekpop_buf(fifo, max, numptr, 0);
fifo->head = 0; }
const uint8_t
*fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr)
{
return fifo8_peekpop_buf(fifo, max, numptr, 1);
}
uint32_t
fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen)
{
const uint8_t *buf;
uint32_t n1, n2 = 0;
uint32_t len;
if (destlen == 0)
return 0;
len = destlen;
buf = fifo8_pop_bufptr(fifo, len, &n1);
if (dest)
memcpy(dest, buf, n1);
/* Add FIFO wraparound if needed */
len -= n1;
len = MIN(len, fifo8_num_used(fifo));
if (len) {
buf = fifo8_pop_bufptr(fifo, len, &n2);
if (dest) {
memcpy(&dest[n1], buf, n2);
}
}
return n1 + n2;
}
void
fifo8_drop(Fifo8 *fifo, uint32_t len)
{
len -= fifo8_pop_buf(fifo, NULL, len);
assert(len == 0);
} }
int int

View File

@@ -69,28 +69,80 @@ extern uint8_t fifo8_pop(Fifo8 *fifo);
/** /**
* fifo8_pop_buf: * fifo8_pop_buf:
* @fifo: FIFO to pop from * @fifo: FIFO to pop from
* @max: maximum number of bytes to pop * @dest: the buffer to write the data into (can be NULL)
* @num: actual number of returned bytes * @destlen: size of @dest and maximum number of bytes to pop
* *
* Pop a number of elements from the FIFO up to a maximum of max. The buffer * Pop a number of elements from the FIFO up to a maximum of @destlen.
* The popped data is copied into the @dest buffer.
* Care is taken when the data wraps around in the ring buffer.
*
* Returns: number of bytes popped.
*/
extern uint32_t fifo8_pop_buf(Fifo8 *fifo, uint8_t *dest, uint32_t destlen);
/**
* fifo8_pop_bufptr:
* @fifo: FIFO to pop from
* @max: maximum number of bytes to pop
* @numptr: pointer filled with number of bytes returned (can be NULL)
*
* New code should prefer to use fifo8_pop_buf() instead of fifo8_pop_bufptr().
*
* Pop a number of elements from the FIFO up to a maximum of @max. The buffer
* containing the popped data is returned. This buffer points directly into * containing the popped data is returned. This buffer points directly into
* the FIFO backing store and data is invalidated once any of the fifo8_* APIs * the internal FIFO backing store and data (without checking for overflow!)
* are called on the FIFO. * and is invalidated once any of the fifo8_* APIs are called on the FIFO.
* *
* The function may return fewer bytes than requested when the data wraps * The function may return fewer bytes than requested when the data wraps
* around in the ring buffer; in this case only a contiguous part of the data * around in the ring buffer; in this case only a contiguous part of the data
* is returned. * is returned.
* *
* The number of valid bytes returned is populated in *num; will always return * The number of valid bytes returned is populated in *@numptr; will always
* at least 1 byte. max must not be 0 or greater than the number of bytes in * return at least 1 byte. max must not be 0 or greater than the number of
* the FIFO. * bytes in the FIFO.
* *
* Clients are responsible for checking the availability of requested data * Clients are responsible for checking the availability of requested data
* using fifo8_num_used(). * using fifo8_num_used().
* *
* Returns: A pointer to popped data. * Returns: A pointer to popped data.
*/ */
extern const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num); extern const uint8_t *fifo8_pop_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr);
/**
* fifo8_peek_bufptr: read upto max bytes from the fifo
* @fifo: FIFO to read from
* @max: maximum number of bytes to peek
* @numptr: pointer filled with number of bytes returned (can be NULL)
*
* Peek into a number of elements from the FIFO up to a maximum of @max.
* The buffer containing the data peeked into is returned. This buffer points
* directly into the FIFO backing store. Since data is invalidated once any
* of the fifo8_* APIs are called on the FIFO, it is the caller responsibility
* to access it before doing further API calls.
*
* The function may return fewer bytes than requested when the data wraps
* around in the ring buffer; in this case only a contiguous part of the data
* is returned.
*
* The number of valid bytes returned is populated in *@numptr; will always
* return at least 1 byte. max must not be 0 or greater than the number of
* bytes in the FIFO.
*
* Clients are responsible for checking the availability of requested data
* using fifo8_num_used().
*
* Returns: A pointer to peekable data.
*/
extern const uint8_t *fifo8_peek_bufptr(Fifo8 *fifo, uint32_t max, uint32_t *numptr);
/**
* fifo8_drop:
* @fifo: FIFO to drop bytes
* @len: number of bytes to drop
*
* Drop (consume) bytes from a FIFO.
*/
extern void fifo8_drop(Fifo8 *fifo, uint32_t len);
/** /**
* fifo8_reset: * fifo8_reset:

View File

@@ -25,6 +25,7 @@
#ifndef SCSI_PCSCSI_H #ifndef SCSI_PCSCSI_H
#define SCSI_PCSCSI_H #define SCSI_PCSCSI_H
extern const device_t am53c974_pci_device;
extern const device_t dc390_pci_device; extern const device_t dc390_pci_device;
extern const device_t ncr53c90a_mca_device; extern const device_t ncr53c90a_mca_device;

View File

@@ -82,6 +82,7 @@ static SCSI_CARD scsi_cards[] = {
{ &ncr53c825a_pci_device, }, { &ncr53c825a_pci_device, },
{ &ncr53c860_pci_device, }, { &ncr53c860_pci_device, },
{ &ncr53c875_pci_device, }, { &ncr53c875_pci_device, },
{ &am53c974_pci_device, },
{ &dc390_pci_device, }, { &dc390_pci_device, },
{ &buslogic_445s_device, }, { &buslogic_445s_device, },
{ &buslogic_445c_device, }, { &buslogic_445c_device, },

View File

@@ -3231,9 +3231,6 @@ begin:
if (dev->drv->bus_type == CDROM_BUS_SCSI) { if (dev->drv->bus_type == CDROM_BUS_SCSI) {
dev->buffer[3] = 0x02; dev->buffer[3] = 0x02;
switch (dev->drv->type) { switch (dev->drv->type) {
case CDROM_TYPE_86BOX_100:
dev->buffer[2] = 0x05; /*SCSI-2 compliant*/
break;
case CDROM_TYPE_CHINON_CDS431_H42: case CDROM_TYPE_CHINON_CDS431_H42:
case CDROM_TYPE_DEC_RRD45_0436: case CDROM_TYPE_DEC_RRD45_0436:
case CDROM_TYPE_MATSHITA_501_10b: case CDROM_TYPE_MATSHITA_501_10b:

File diff suppressed because it is too large Load Diff