Spring cleanup of macros

This commit is contained in:
Søren Schmidt 2004-04-30 16:21:34 +00:00
parent d1d669bd76
commit ad452ba45c
11 changed files with 45 additions and 100 deletions

View File

@ -120,7 +120,7 @@ ata_probe(device_t dev)
ch->device[SLAVE].unit = ATA_SLAVE;
ch->device[SLAVE].mode = ATA_PIO;
ch->dev = dev;
ch->state = ATA_IDLE;
ch->lock = ATA_IDLE;
/* initialise device(s) on this channel */
ch->locking(ch, ATA_LF_LOCK);
@ -236,7 +236,7 @@ ata_reinit(struct ata_channel *ch)
/* reset the HW */
if (bootverbose)
ata_printf(ch, -1, "reiniting channel ..\n");
ATA_FORCELOCK_CH(ch, ATA_CONTROL);
ATA_FORCELOCK_CH(ch);
ch->flags |= ATA_IMMEDIATE_MODE;
ch->running = NULL;
devices = ch->devices;
@ -317,7 +317,7 @@ ata_suspend(device_t dev)
return ENXIO;
ch->locking(ch, ATA_LF_LOCK);
ATA_SLEEPLOCK_CH(ch, ATA_CONTROL);
ATA_SLEEPLOCK_CH(ch);
return 0;
}

View File

@ -350,10 +350,9 @@ struct ata_channel {
#define ATA_ATAPI_MASTER 0x04
#define ATA_ATAPI_SLAVE 0x08
int state; /* ATA channel state control */
int lock; /* ATA channel lock */
#define ATA_IDLE 0x0000
#define ATA_ACTIVE 0x0001
#define ATA_CONTROL 0x0002
void (*reset)(struct ata_channel *);
void (*locking)(struct ata_channel *, int);
@ -425,16 +424,17 @@ extern uma_zone_t ata_zone;
#define ata_free_request(request) uma_zfree(ata_zone, request)
/* macros for locking a channel */
#define ATA_LOCK_CH(ch, value) \
atomic_cmpset_acq_int(&(ch)->state, ATA_IDLE, (value))
#define ATA_LOCK_CH(ch) \
atomic_cmpset_acq_int(&(ch)->lock, ATA_IDLE, ATA_ACTIVE)
#define ATA_SLEEPLOCK_CH(ch, value) \
while (!atomic_cmpset_acq_int(&(ch)->state, ATA_IDLE, (value))) \
tsleep((caddr_t)&(ch), PRIBIO, "atalck", 1);
#define ATA_SLEEPLOCK_CH(ch) \
while (!ATA_LOCK_CH(ch)) tsleep((caddr_t)&(ch), PRIBIO, "atalck", 1);
#define ATA_FORCELOCK_CH(ch, value) atomic_store_rel_int(&(ch)->state, (value))
#define ATA_FORCELOCK_CH(ch) \
atomic_store_rel_int(&(ch)->lock, ATA_ACTIVE)
#define ATA_UNLOCK_CH(ch) atomic_store_rel_int(&(ch)->state, ATA_IDLE)
#define ATA_UNLOCK_CH(ch) \
atomic_store_rel_int(&(ch)->lock, ATA_IDLE)
/* macros to hide busspace uglyness */
#define ATA_INB(res, offset) \
@ -489,101 +489,44 @@ extern uma_zone_t ata_zone;
rman_get_bushandle((res)), \
(offset), (addr), (count))
#define ATA_IDX_SET(ch, idx) \
ATA_OUTB(ch->r_io[ATA_IDX_ADDR].res, ch->r_io[ATA_IDX_ADDR].offset, \
ch->r_io[idx].offset)
#define ATA_IDX_INB(ch, idx) \
((ch->r_io[idx].res) \
? ATA_INB(ch->r_io[idx].res, ch->r_io[idx].offset) \
: (ATA_IDX_SET(ch, idx), \
ATA_INB(ch->r_io[ATA_IDX_DATA].res, ch->r_io[ATA_IDX_DATA].offset)))
ATA_INB(ch->r_io[idx].res, ch->r_io[idx].offset)
#define ATA_IDX_INW(ch, idx) \
((ch->r_io[idx].res) \
? ATA_INW(ch->r_io[idx].res, ch->r_io[idx].offset) \
: (ATA_IDX_SET(ch, idx), \
ATA_INW(ch->r_io[ATA_IDX_DATA].res, ch->r_io[ATA_IDX_DATA].offset)))
ATA_INW(ch->r_io[idx].res, ch->r_io[idx].offset)
#define ATA_IDX_INL(ch, idx) \
((ch->r_io[idx].res) \
? ATA_INL(ch->r_io[idx].res, ch->r_io[idx].offset) \
: (ATA_IDX_SET(ch, idx), \
ATA_INL(ch->r_io[ATA_IDX_DATA].res, ch->r_io[ATA_IDX_DATA].offset)))
ATA_INL(ch->r_io[idx].res, ch->r_io[idx].offset)
#define ATA_IDX_INSW(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_INSW(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_INSW(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_INSW(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_INSW_STRM(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_INSW_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_INSW_STRM(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_INSW_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_INSL(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_INSL(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_INSL(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_INSL(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_INSL_STRM(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_INSL_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_INSL_STRM(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_INSL_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_OUTB(ch, idx, value) \
((ch->r_io[idx].res) \
? ATA_OUTB(ch->r_io[idx].res, ch->r_io[idx].offset, value) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTB(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, value)))
ATA_OUTB(ch->r_io[idx].res, ch->r_io[idx].offset, value)
#define ATA_IDX_OUTW(ch, idx, value) \
((ch->r_io[idx].res) \
? ATA_OUTW(ch->r_io[idx].res, ch->r_io[idx].offset, value) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTW(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, value)))
ATA_OUTW(ch->r_io[idx].res, ch->r_io[idx].offset, value)
#define ATA_IDX_OUTL(ch, idx, value) \
((ch->r_io[idx].res) \
? ATA_OUTL(ch->r_io[idx].res, ch->r_io[idx].offset, value) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTL(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, value)))
ATA_OUTL(ch->r_io[idx].res, ch->r_io[idx].offset, value)
#define ATA_IDX_OUTSW(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_OUTSW(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTSW(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_OUTSW(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_OUTSW_STRM(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_OUTSW_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTSW_STRM(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_OUTSW_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_OUTSL(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_OUTSL(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTSL(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_OUTSL(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)
#define ATA_IDX_OUTSL_STRM(ch, idx, addr, count) \
((ch->r_io[idx].res) \
? ATA_OUTSL_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count) \
: (ATA_IDX_SET(ch, idx), \
ATA_OUTSL_STRM(ch->r_io[ATA_IDX_DATA].res, \
ch->r_io[ATA_IDX_DATA].offset, addr, count)))
ATA_OUTSL_STRM(ch->r_io[idx].res, ch->r_io[idx].offset, addr, count)

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -43,6 +43,8 @@
#define ATA_WRITE_DMA48 0x35 /* write w/DMA command */
#define ATA_WRITE_DMA_QUEUED48 0x36 /* write w/DMA QUEUED command */
#define ATA_WRITE_MUL48 0x39 /* write multi command */
#define ATA_READ_FPDMA_QUEUED 0x60 /* read w/DMA NCQ */
#define ATA_WRITE_FPDMA_QUEUED 0x61 /* write w/DMA NCQ */
#define ATA_PACKET_CMD 0xa0 /* packet command */
#define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/
#define ATA_SERVICE 0xa2 /* service command */

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -45,7 +45,7 @@ struct ad_softc {
#define AD_F_TAG_ENABLED 0x0008
#define AD_F_RAID_SUBDISK 0x0010
struct mtx queue_mtx; /* queue lock */
struct mtx queue_mtx; /* bio queue lock */
struct bio_queue_head queue; /* head of request queue */
struct disk *disk; /* disklabel/slice stuff */
};

View File

@ -59,7 +59,7 @@ static struct isa_pnp_id ata_ids[] = {
};
static void
ata_isa_lock(struct ata_channel *ch, int type)
ata_isa_locknoop(struct ata_channel *ch, int type)
{
}
@ -114,7 +114,7 @@ ata_isa_probe(device_t dev)
/* initialize softc for this channel */
ch->unit = 0;
ch->flags |= ATA_USE_16BIT;
ch->locking = ata_isa_lock;
ch->locking = ata_isa_locknoop;
ch->device[MASTER].setmode = ata_isa_setmode;
ch->device[SLAVE].setmode = ata_isa_setmode;
ata_generic_hw(ch);

View File

@ -289,7 +289,7 @@ ata_generic_interrupt(void *data)
/* ignore this interrupt if there is no running request */
if (!request) {
if (ATA_LOCK_CH(ch, ATA_CONTROL)) {
if (ATA_LOCK_CH(ch)) {
u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
u_int8_t error = ATA_IDX_INB(ch, ATA_ERROR);

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 2003, 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -163,7 +163,7 @@ ata_start(struct ata_channel *ch)
/* lock the ATA HW for this request */
mtx_lock(&ch->queue_mtx);
ch->locking(ch, ATA_LF_LOCK);
if (!ATA_LOCK_CH(ch, ATA_ACTIVE)) {
if (!ATA_LOCK_CH(ch)) {
mtx_unlock(&ch->queue_mtx);
return;
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -301,7 +301,7 @@ struct acd_softc {
int flags; /* device state flags */
#define F_LOCKED 0x0001 /* this unit is locked */
struct mtx queue_mtx; /* queue lock */
struct mtx queue_mtx; /* bio queue lock */
struct bio_queue_head queue; /* queue of i/o requests */
struct toc toc; /* table of disc contents */
struct audiopage au; /* audio page info */
@ -312,9 +312,9 @@ struct acd_softc {
struct acd_softc **driver; /* softc's of changer slots */
int slot; /* this instance slot number */
time_t timestamp; /* this instance timestamp */
u_int disk_size; /* size of current media */
u_int block_size; /* blocksize currently used */
u_int32_t disk_size; /* size of current media */
u_int32_t block_size; /* blocksize currently used */
u_int32_t iomax; /* Max I/O request (bytes) */
struct g_geom *gp; /* geom instance */
struct g_provider *pp[MAXTRK+1]; /* providers */
u_int iomax; /* Max I/O request (bytes) */
};

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -71,7 +71,7 @@ struct afd_cappage {
struct afd_softc {
struct ata_device *device; /* device softc */
int lun; /* logical device unit */
struct mtx queue_mtx; /* queue lock */
struct mtx queue_mtx; /* bio queue lock */
struct bio_queue_head queue; /* queue of i/o requests */
struct afd_cappage cap; /* capabilities page info */
struct disk *disk; /* virtual drives */

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1998 - 2003 Søren Schmidt <sos@FreeBSD.org>
* Copyright (c) 1998 - 2004 Søren Schmidt <sos@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -154,7 +154,7 @@ struct ast_softc {
#define F_ONSTREAM 0x0100 /* OnStream ADR device */
int blksize; /* block size (512 | 1024) */
struct mtx queue_mtx; /* queue lock */
struct mtx queue_mtx; /* bio queue lock */
struct bio_queue_head queue; /* queue of i/o requests */
struct atapi_params *param; /* drive parameters table */
struct ast_cappage cap; /* capabilities page info */