- u_intNN_t -> uintNN_t

- ANSI function decls
- ntohl -> be32toh, htonl -> htobe32, htons -> htobe16
- bcopy -> memcpy, bcmp -> memcmp, bzero -> memset
- some KNF
This commit is contained in:
tsutsui 2005-02-19 15:40:15 +00:00
parent cb6453db10
commit eff817e362
3 changed files with 185 additions and 257 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: maple.c,v 1.26 2003/07/15 01:31:39 lukem Exp $ */
/* $NetBSD: maple.c,v 1.27 2005/02/19 15:40:15 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: maple.c,v 1.26 2003/07/15 01:31:39 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: maple.c,v 1.27 2005/02/19 15:40:15 tsutsui Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -181,7 +181,7 @@ static int
maplematch(struct device *parent, struct cfdata *cf, void *aux)
{
return (1);
return 1;
}
static void
@ -191,7 +191,7 @@ mapleattach(struct device *parent, struct device *self, void *aux)
struct maple_unit *u;
vaddr_t dmabuffer;
paddr_t dmabuffer_phys;
u_int32_t *p;
uint32_t *p;
int port, subunit, f;
sc = (struct maple_softc *)self;
@ -204,9 +204,9 @@ mapleattach(struct device *parent, struct device *self, void *aux)
return;
}
p = (u_int32_t *)dmabuffer;
p = (uint32_t *)dmabuffer;
for (port = 0; port < MAPLE_PORTS; port++)
for (port = 0; port < MAPLE_PORTS; port++) {
for (subunit = 0; subunit < MAPLE_SUBUNITS; subunit++) {
u = &sc->sc_unit[port][subunit];
u->port = port;
@ -221,6 +221,7 @@ mapleattach(struct device *parent, struct device *self, void *aux)
u->u_func[f].f_unit = u;
}
}
}
sc->sc_txbuf = p;
sc->sc_txbuf_phys = SH3_P2SEG_TO_PHYS(p);
@ -378,13 +379,13 @@ maple_alloc_dma(size_t size, vaddr_t *vap, paddr_t *pap)
error = uvm_pglistalloc(size, avail_start, avail_end - PAGE_SIZE,
0, 0, &mlist, 1, 0);
if (error)
return (error);
return error;
m = TAILQ_FIRST(&mlist);
*pap = VM_PAGE_TO_PHYS(m);
*vap = SH3_PHYS_TO_P2SEG(VM_PAGE_TO_PHYS(m));
return (0);
return 0;
}
#if 0 /* currently unused */
@ -419,11 +420,11 @@ maple_end_txbuf(struct maple_softc *sc)
/* if no frame have been written, we can't mark the
list end, and so the DMA must not be activated */
if (sc->sc_txpos == sc->sc_txbuf)
return (0);
return 0;
*sc->sc_txlink |= 0x80000000;
return (1);
return 1;
}
static const int8_t subunit_code[] = { 0x20, 0x01, 0x02, 0x04, 0x08, 0x10 };
@ -433,7 +434,7 @@ maple_queue_command(struct maple_softc *sc, struct maple_unit *u,
int command, int datalen, const void *dataaddr)
{
int to, from;
u_int32_t *p = sc->sc_txpos;
uint32_t *p = sc->sc_txpos;
/* Max data length = 255 longs = 1020 bytes */
KASSERT(datalen >= 0 && datalen <= 255);
@ -457,7 +458,7 @@ maple_queue_command(struct maple_softc *sc, struct maple_unit *u,
/* Copy parameter data, if any */
if (datalen > 0) {
const u_int32_t *param = dataaddr;
const uint32_t *param = dataaddr;
int i;
for (i = 0; i < datalen; i++)
*p++ = *param++;
@ -616,10 +617,10 @@ maple_print_unit(void *aux, const char *pnp)
printf(": a %#x c %#x fn %#x d %#x,%#x,%#x",
ma->ma_devinfo->di_area_code,
ma->ma_devinfo->di_connector_direction,
ntohl(ma->ma_devinfo->di_func),
ntohl(ma->ma_devinfo->di_function_data[0]),
ntohl(ma->ma_devinfo->di_function_data[1]),
ntohl(ma->ma_devinfo->di_function_data[2]));
be32toh(ma->ma_devinfo->di_func),
be32toh(ma->ma_devinfo->di_function_data[0]),
be32toh(ma->ma_devinfo->di_function_data[1]),
be32toh(ma->ma_devinfo->di_function_data[2]));
#endif
/* nul termination */
@ -642,13 +643,13 @@ maplesubmatch(struct device *parent, struct cfdata *match, void *aux)
if (match->cf_loc[MAPLECF_PORT] != MAPLECF_PORT_DEFAULT &&
match->cf_loc[MAPLECF_PORT] != ma->ma_unit->port)
return (0);
return 0;
if (match->cf_loc[MAPLECF_SUBUNIT] != MAPLECF_SUBUNIT_DEFAULT &&
match->cf_loc[MAPLECF_SUBUNIT] != ma->ma_unit->subunit)
return (0);
return 0;
return (config_match(parent, match, aux));
return config_match(parent, match, aux);
}
static int
@ -674,14 +675,14 @@ static void
maple_attach_unit(struct maple_softc *sc, struct maple_unit *u)
{
struct maple_attach_args ma;
u_int32_t func;
uint32_t func;
int f;
char oldxname[16];
ma.ma_unit = u;
ma.ma_devinfo = &u->devinfo;
ma.ma_basedevinfo = &sc->sc_unit[u->port][0].devinfo;
func = ntohl(ma.ma_devinfo->di_func);
func = be32toh(ma.ma_devinfo->di_func);
maple_print_unit(&ma, sc->sc_dev.dv_xname);
printf("\n");
@ -974,8 +975,8 @@ maple_unit_ping(struct maple_softc *sc)
struct maple_unit *u;
struct maple_func *fn;
#ifdef MAPLE_MEMCARD_PING_HACK
static const u_int32_t memcard_ping_arg[2] = {
0x02000000, /* htonl(MAPLE_FUNC(MAPLE_FN_MEMCARD)) */
static const uint32_t memcard_ping_arg[2] = {
0x02000000, /* htobe32(MAPLE_FUNC(MAPLE_FN_MEMCARD)) */
0 /* pt (1 byte) and unused 3 bytes */
};
#endif
@ -994,7 +995,7 @@ maple_unit_ping(struct maple_softc *sc)
#endif
{
fn = &u->u_func[u->u_ping_func];
fn->f_work = htonl(MAPLE_FUNC(u->u_ping_func));
fn->f_work = htobe32(MAPLE_FUNC(u->u_ping_func));
maple_write_command(sc, u,
MAPLE_COMMAND_GETCOND,
1, &fn->f_work);
@ -1071,7 +1072,7 @@ maple_send_defered_periodic(struct maple_softc *sc)
/*
* queue periodic command
*/
fn->f_work = htonl(MAPLE_FUNC(fn->f_funcno));
fn->f_work = htobe32(MAPLE_FUNC(fn->f_funcno));
maple_write_command(sc, u,
MAPLE_COMMAND_GETCOND, 1, &fn->f_work);
u->u_dma_stat = MAPLE_DMA_PERIODIC;
@ -1112,7 +1113,7 @@ maple_send_periodic(struct maple_softc *sc)
/*
* queue periodic command
*/
fn->f_work = htonl(MAPLE_FUNC(fn->f_funcno));
fn->f_work = htobe32(MAPLE_FUNC(fn->f_funcno));
maple_write_command(sc, u, MAPLE_COMMAND_GETCOND,
1, &fn->f_work);
u->u_dma_stat = MAPLE_DMA_PERIODIC;
@ -1251,7 +1252,7 @@ maple_check_responses(struct maple_softc *sc)
u->u_dma_stat = MAPLE_DMA_IDLE;
func_code = u->u_dma_func;
if (response == MAPLE_RESPONSE_DATATRF && len > 0 &&
ntohl(u->u_rxbuf[1]) == MAPLE_FUNC(func_code)) {
be32toh(u->u_rxbuf[1]) == MAPLE_FUNC(func_code)) {
fn = &u->u_func[func_code];
if (fn->f_dev)
(*fn->f_callback)(fn->f_arg,
@ -1588,23 +1589,23 @@ maple_set_callback(struct device *dev, struct maple_unit *u, int func,
/*
* Return function definition data (called by drivers)
*/
u_int32_t
uint32_t
maple_get_function_data(struct maple_devinfo *devinfo, int function_code)
{
int i, p = 0;
u_int32_t func;
uint32_t func;
func = ntohl(devinfo->di_func);
func = be32toh(devinfo->di_func);
for (i = 31; i >= 0; --i)
if (func & MAPLE_FUNC(i)) {
if (function_code == i)
return ntohl(devinfo->di_function_data[p]);
return be32toh(devinfo->di_function_data[p]);
else
if (++p >= 3)
break;
}
return (0);
return 0;
}
/* Generic maple device interface */
@ -1616,20 +1617,20 @@ mapleopen(dev_t dev, int flag, int mode, struct proc *p)
sc = device_lookup(&maple_cd, MAPLEBUSUNIT(dev));
if (sc == NULL) /* make sure it was attached */
return (ENXIO);
return ENXIO;
if (MAPLEPORT(dev) >= MAPLE_PORTS)
return (ENXIO);
return ENXIO;
if (MAPLESUBUNIT(dev) >= MAPLE_SUBUNITS)
return (ENXIO);
return ENXIO;
if (!(sc->sc_port_units[MAPLEPORT(dev)] & (1 << MAPLESUBUNIT(dev))))
return (ENXIO);
return ENXIO;
sc->sc_port_units_open[MAPLEPORT(dev)] |= 1 << MAPLESUBUNIT(dev);
return (0);
return 0;
}
int
@ -1641,7 +1642,7 @@ mapleclose(dev_t dev, int flag, int mode, struct proc *p)
sc->sc_port_units_open[MAPLEPORT(dev)] &= ~(1 << MAPLESUBUNIT(dev));
return (0);
return 0;
}
int
@ -1651,17 +1652,17 @@ maple_unit_ioctl(struct device *dev, struct maple_unit *u, u_long cmd,
struct maple_softc *sc = (struct maple_softc *)dev;
if (!(sc->sc_port_units[u->port] & (1 << u->subunit)))
return (ENXIO);
return ENXIO;
switch(cmd) {
case MAPLEIO_GDEVINFO:
memcpy(data, &u->devinfo, sizeof(struct maple_devinfo));
break;
default:
return (EPASSTHROUGH);
return EPASSTHROUGH;
}
return (0);
return 0;
}
int
@ -1673,5 +1674,5 @@ mapleioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
sc = device_lookup(&maple_cd, MAPLEBUSUNIT(dev));
u = &sc->sc_unit[MAPLEPORT(dev)][MAPLESUBUNIT(dev)];
return (maple_unit_ioctl(&sc->sc_dev, u, cmd, data, flag, p));
return maple_unit_ioctl(&sc->sc_dev, u, cmd, data, flag, p);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mlcd.c,v 1.3 2003/07/15 01:31:40 lukem Exp $ */
/* $NetBSD: mlcd.c,v 1.4 2005/02/19 15:40:16 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mlcd.c,v 1.3 2003/07/15 01:31:40 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: mlcd.c,v 1.4 2005/02/19 15:40:16 tsutsui Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -64,27 +64,27 @@ struct mlcd_funcdef { /* XXX assuming little-endian structure packing */
};
struct mlcd_request_write_data {
u_int32_t func_code;
u_int8_t pt;
u_int8_t phase; /* 0, 1, 2, 3: for each 128 byte */
u_int16_t block;
u_int8_t data[MLCD_MAXACCSIZE];
uint32_t func_code;
uint8_t pt;
uint8_t phase; /* 0, 1, 2, 3: for each 128 byte */
uint16_t block;
uint8_t data[MLCD_MAXACCSIZE];
};
#define MLCD_SIZE_REQW(sc) ((sc)->sc_waccsz + 8)
struct mlcd_request_get_media_info {
u_int32_t func_code;
u_int32_t pt; /* pt (1 byte) and unused 3 bytes */
uint32_t func_code;
uint32_t pt; /* pt (1 byte) and unused 3 bytes */
};
struct mlcd_media_info {
u_int8_t width; /* width - 1 */
u_int8_t height; /* height - 1 */
u_int8_t rsvd[2]; /* ? 0x10 0x02 */
uint8_t width; /* width - 1 */
uint8_t height; /* height - 1 */
uint8_t rsvd[2]; /* ? 0x10 0x02 */
};
struct mlcd_response_media_info {
u_int32_t func_code; /* function code (big endian) */
uint32_t func_code; /* function code (big endian) */
struct mlcd_media_info info;
};
@ -93,7 +93,7 @@ struct mlcd_buf {
int lb_error;
int lb_partno;
int lb_blkno;
u_int32_t lb_data[1]; /* variable length */
uint32_t lb_data[1]; /* variable length */
};
#define MLCD_BUF_SZ(sc) (offsetof(struct mlcd_buf, lb_data) + (sc)->sc_bsize)
@ -155,18 +155,18 @@ struct mlcd_softc {
#define MLCD_UNIT(dev) (minor(dev) >> 8)
#define MLCD_MINOR(unit, part) (((unit) << 8) | (part))
static int mlcdmatch __P((struct device *, struct cfdata *, void *));
static void mlcdattach __P((struct device *, struct device *, void *));
static int mlcddetach __P((struct device *, int));
static void mlcd_intr __P((void *, struct maple_response *, int, int));
static void mlcd_printerror __P((const char *, u_int32_t));
static struct mlcd_buf *mlcd_buf_alloc __P((int /*dev*/, int /*flags*/));
static void mlcd_buf_free __P((struct mlcd_buf *));
static __inline u_int32_t reverse_32 __P((u_int32_t));
static void mlcd_rotate_bitmap __P((void *, size_t));
static void mlcdstart __P((struct mlcd_softc *));
static void mlcdstart_bp __P((struct mlcd_softc *));
static void mlcddone __P((struct mlcd_softc *));
static int mlcdmatch(struct device *, struct cfdata *, void *);
static void mlcdattach(struct device *, struct device *, void *);
static int mlcddetach(struct device *, int);
static void mlcd_intr(void *, struct maple_response *, int, int);
static void mlcd_printerror(const char *, uint32_t);
static struct mlcd_buf *mlcd_buf_alloc(int /*dev*/, int /*flags*/);
static void mlcd_buf_free(struct mlcd_buf *);
static __inline uint32_t reverse_32(uint32_t);
static void mlcd_rotate_bitmap(void *, size_t);
static void mlcdstart(struct mlcd_softc *);
static void mlcdstart_bp(struct mlcd_softc *);
static void mlcddone(struct mlcd_softc *);
dev_type_open(mlcdopen);
dev_type_close(mlcdclose);
@ -205,10 +205,7 @@ static const char initimg48x32[192] = {
/* ARGSUSED */
static int
mlcdmatch(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
mlcdmatch(struct device *parent, struct cfdata *cf, void *aux)
{
struct maple_attach_args *ma = aux;
@ -216,15 +213,13 @@ mlcdmatch(parent, cf, aux)
}
static void
mlcdattach(parent, self, aux)
struct device *parent, *self;
void *aux;
mlcdattach(struct device *parent, struct device *self, void *aux)
{
struct mlcd_softc *sc = (void *) self;
struct maple_attach_args *ma = aux;
int i;
union {
u_int32_t v;
uint32_t v;
struct mlcd_funcdef s;
} funcdef;
@ -286,7 +281,7 @@ mlcdattach(parent, self, aux)
/*
* get size (start from partition 0)
*/
sc->sc_reqm.func_code = htonl(MAPLE_FUNC(MAPLE_FN_LCD));
sc->sc_reqm.func_code = htobe32(MAPLE_FUNC(MAPLE_FN_LCD));
sc->sc_reqm.pt = 0;
maple_command(sc->sc_parent, sc->sc_unit, MAPLE_FN_LCD,
MAPLE_COMMAND_GETMINFO, sizeof sc->sc_reqm / 4, &sc->sc_reqm, 0);
@ -294,9 +289,7 @@ mlcdattach(parent, self, aux)
/* ARGSUSED1 */
static int
mlcddetach(self, flags)
struct device *self;
int flags;
mlcddetach(struct device *self, int flags)
{
struct mlcd_softc *sc = (struct mlcd_softc *) self;
struct mlcd_buf *bp;
@ -338,10 +331,7 @@ mlcddetach(self, flags)
*/
/* ARGSUSED3 */
static void
mlcd_intr(dev, response, sz, flags)
void *dev;
struct maple_response *response;
int sz, flags;
mlcd_intr(void *dev, struct maple_response *response, int sz, int flags)
{
struct mlcd_softc *sc = dev;
struct mlcd_response_media_info *rm = (void *) response->data;
@ -371,7 +361,7 @@ mlcd_intr(dev, response, sz, flags)
break;
default:
printf("%s: init: unexpected response %#x, sz %d\n",
pt->pt_name, ntohl(response->response_code), sz);
pt->pt_name, be32toh(response->response_code), sz);
break;
}
if (++part == sc->sc_npt) {
@ -383,11 +373,11 @@ mlcd_intr(dev, response, sz, flags)
sc->sc_wacc == 1) {
sc->sc_stat = MLCD_INIT2;
sc->sc_reqw.func_code =
htonl(MAPLE_FUNC(MAPLE_FN_LCD));
htobe32(MAPLE_FUNC(MAPLE_FN_LCD));
sc->sc_reqw.pt = 0; /* part 0 */
sc->sc_reqw.block = 0;
sc->sc_reqw.phase = 0;
bcopy(initimg48x32, sc->sc_reqw.data,
memcpy(sc->sc_reqw.data, initimg48x32,
sizeof initimg48x32);
if (sc->sc_direction == MAPLE_CONN_TOP) {
/* the LCD is upside-down */
@ -421,9 +411,10 @@ mlcd_intr(dev, response, sz, flags)
mlcddone(sc);
} else {
/* go next phase */
bcopy((char *)bp->lb_data
+ sc->sc_waccsz * sc->sc_reqw.phase,
sc->sc_reqw.data, sc->sc_waccsz);
memcpy(sc->sc_reqw.data,
(char *)bp->lb_data +
sc->sc_waccsz * sc->sc_reqw.phase,
sc->sc_waccsz);
maple_command(sc->sc_parent, sc->sc_unit,
MAPLE_FN_LCD, MAPLE_COMMAND_BWRITE,
MLCD_SIZE_REQW(sc) / 4, &sc->sc_reqw, 0);
@ -437,8 +428,8 @@ mlcd_intr(dev, response, sz, flags)
default:
printf("%s: write: unexpected response %#x, %#x, sz %d\n",
sc->sc_pt[sc->sc_reqw.pt].pt_name,
ntohl(response->response_code),
ntohl(rm->func_code), sz);
be32toh(response->response_code),
be32toh(rm->func_code), sz);
mlcdstart_bp(sc); /* retry */
break;
}
@ -450,9 +441,7 @@ mlcd_intr(dev, response, sz, flags)
}
static void
mlcd_printerror(head, code)
const char *head;
u_int32_t code;
mlcd_printerror(const char *head, uint32_t code)
{
printf("%s:", head);
@ -474,10 +463,7 @@ mlcd_printerror(head, code)
/* ARGSUSED */
int
mlcdopen(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
mlcdopen(dev_t dev, int flags, int devtype, struct proc *p)
{
int unit, part;
struct mlcd_softc *sc;
@ -501,10 +487,7 @@ mlcdopen(dev, flags, devtype, p)
/* ARGSUSED */
int
mlcdclose(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
mlcdclose(dev_t dev, int flags, int devtype, struct proc *p)
{
int unit, part;
struct mlcd_softc *sc;
@ -524,8 +507,7 @@ mlcdclose(dev, flags, devtype, p)
* start I/O operations
*/
static void
mlcdstart(sc)
struct mlcd_softc *sc;
mlcdstart(struct mlcd_softc *sc)
{
struct mlcd_buf *bp;
@ -547,8 +529,7 @@ mlcdstart(sc)
* start/retry a specified I/O operation
*/
static void
mlcdstart_bp(sc)
struct mlcd_softc *sc;
mlcdstart_bp(struct mlcd_softc *sc)
{
struct mlcd_buf *bp;
struct mlcd_pt *pt;
@ -576,19 +557,18 @@ mlcdstart_bp(sc)
*/
/* write */
sc->sc_stat = MLCD_WRITE;
sc->sc_reqw.func_code = htonl(MAPLE_FUNC(MAPLE_FN_LCD));
sc->sc_reqw.func_code = htobe32(MAPLE_FUNC(MAPLE_FN_LCD));
sc->sc_reqw.pt = bp->lb_partno;
sc->sc_reqw.block = htons(bp->lb_blkno);
sc->sc_reqw.block = htobe16(bp->lb_blkno);
sc->sc_reqw.phase = 0; /* first phase */
bcopy((char *) bp->lb_data /* + sc->sc_waccsz * phase */,
sc->sc_reqw.data, sc->sc_waccsz);
memcpy(sc->sc_reqw.data,
(char *) bp->lb_data /* + sc->sc_waccsz * phase */, sc->sc_waccsz);
maple_command(sc->sc_parent, sc->sc_unit, MAPLE_FN_LCD,
MAPLE_COMMAND_BWRITE, MLCD_SIZE_REQW(sc) / 4, &sc->sc_reqw, 0);
}
static void
mlcddone(sc)
struct mlcd_softc *sc;
mlcddone(struct mlcd_softc *sc)
{
struct mlcd_buf *bp;
@ -610,9 +590,7 @@ mlcddone(sc)
* [flags == M_WAITOK] device detach detected
*/
static struct mlcd_buf *
mlcd_buf_alloc(dev, flags)
int dev;
int flags; /* flags for malloc() */
mlcd_buf_alloc(int dev, int flags)
{
struct mlcd_softc *sc;
struct mlcd_pt *pt;
@ -648,19 +626,17 @@ mlcd_buf_alloc(dev, flags)
}
static void
mlcd_buf_free(bp)
struct mlcd_buf *bp;
mlcd_buf_free(struct mlcd_buf *bp)
{
free(bp, M_DEVBUF);
}
/* invert order of bits */
static __inline u_int32_t
reverse_32(b)
u_int32_t b;
static __inline uint32_t
reverse_32(uint32_t b)
{
u_int32_t b1;
uint32_t b1;
/* invert every 8bit */
b1 = (b & 0x55555555) << 1; b = (b >> 1) & 0x55555555; b |= b1;
@ -672,13 +648,11 @@ reverse_32(b)
}
static void
mlcd_rotate_bitmap(ptr, size)
void *ptr;
size_t size;
mlcd_rotate_bitmap(void *ptr, size_t size)
{
u_int32_t *p, *q, tmp;
uint32_t *p, *q, tmp;
KDASSERT(size % sizeof(u_int32_t) == 0);
KDASSERT(size % sizeof(uint32_t) == 0);
for (p = ptr, q = (void *)((char *)ptr + size); p < q; ) {
tmp = reverse_32(*p);
*p++ = reverse_32(*--q);
@ -688,10 +662,7 @@ mlcd_rotate_bitmap(ptr, size)
/* ARGSUSED2 */
int
mlcdwrite(dev, uio, flags)
dev_t dev;
struct uio *uio;
int flags;
mlcdwrite(dev_t dev, struct uio *uio, int flags)
{
struct mlcd_softc *sc;
struct mlcd_pt *pt;
@ -753,12 +724,7 @@ mlcdwrite(dev, uio, flags)
}
int
mlcdioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
mlcdioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
{
int unit, part;
struct mlcd_softc *sc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mmemcard.c,v 1.4 2004/10/28 07:07:36 yamt Exp $ */
/* $NetBSD: mmemcard.c,v 1.5 2005/02/19 15:40:16 tsutsui Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mmemcard.c,v 1.4 2004/10/28 07:07:36 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: mmemcard.c,v 1.5 2005/02/19 15:40:16 tsutsui Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@ -67,44 +67,44 @@ struct mmem_funcdef { /* XXX assuming little-endian structure packing */
};
struct mmem_request_read_data {
u_int32_t func_code;
u_int8_t pt;
u_int8_t phase;
u_int16_t block;
uint32_t func_code;
uint8_t pt;
uint8_t phase;
uint16_t block;
};
struct mmem_response_read_data {
u_int32_t func_code; /* function code (big endian) */
u_int32_t blkno; /* 512byte block number (big endian) */
u_int8_t data[MMEM_MAXACCSIZE];
uint32_t func_code; /* function code (big endian) */
uint32_t blkno; /* 512byte block number (big endian) */
uint8_t data[MMEM_MAXACCSIZE];
};
struct mmem_request_write_data {
u_int32_t func_code;
u_int8_t pt;
u_int8_t phase; /* 0, 1, 2, 3: for each 128 byte */
u_int16_t block;
u_int8_t data[MMEM_MAXACCSIZE];
uint32_t func_code;
uint8_t pt;
uint8_t phase; /* 0, 1, 2, 3: for each 128 byte */
uint16_t block;
uint8_t data[MMEM_MAXACCSIZE];
};
#define MMEM_SIZE_REQW(sc) ((sc)->sc_waccsz + 8)
struct mmem_request_get_media_info {
u_int32_t func_code;
u_int32_t pt; /* pt (1 byte) and unused 3 bytes */
uint32_t func_code;
uint32_t pt; /* pt (1 byte) and unused 3 bytes */
};
struct mmem_media_info {
u_int16_t maxblk, minblk;
u_int16_t infpos;
u_int16_t fatpos, fatsz;
u_int16_t dirpos, dirsz;
u_int16_t icon;
u_int16_t datasz;
u_int16_t rsvd[3];
uint16_t maxblk, minblk;
uint16_t infpos;
uint16_t fatpos, fatsz;
uint16_t dirpos, dirsz;
uint16_t icon;
uint16_t datasz;
uint16_t rsvd[3];
};
struct mmem_response_media_info {
u_int32_t func_code; /* function code (big endian) */
uint32_t func_code; /* function code (big endian) */
struct mmem_media_info info;
};
@ -174,17 +174,17 @@ struct mmem_softc {
#define MMEM_DISKMINOR(unit, part, disklabel_partition) \
DISKMINOR(((unit) << 8) | (part), (disklabel_partition))
static int mmemmatch __P((struct device *, struct cfdata *, void *));
static void mmemattach __P((struct device *, struct device *, void *));
static void mmem_defaultlabel __P((struct mmem_softc *, struct mmem_pt *,
struct disklabel *));
static int mmemdetach __P((struct device *, int));
static void mmem_intr __P((void *, struct maple_response *, int, int));
static void mmem_printerror __P((const char *, int, int, u_int32_t));
static void mmemstart __P((struct mmem_softc *));
static void mmemstart_bp __P((struct mmem_softc *));
static void mmemstart_write2 __P((struct mmem_softc *));
static void mmemdone __P((struct mmem_softc *, struct mmem_pt *, int));
static int mmemmatch(struct device *, struct cfdata *, void *);
static void mmemattach(struct device *, struct device *, void *);
static void mmem_defaultlabel(struct mmem_softc *, struct mmem_pt *,
struct disklabel *);
static int mmemdetach(struct device *, int);
static void mmem_intr(void *, struct maple_response *, int, int);
static void mmem_printerror(const char *, int, int, uint32_t);
static void mmemstart(struct mmem_softc *);
static void mmemstart_bp(struct mmem_softc *);
static void mmemstart_write2(struct mmem_softc *);
static void mmemdone(struct mmem_softc *, struct mmem_pt *, int);
dev_type_open(mmemopen);
dev_type_close(mmemclose);
@ -211,26 +211,21 @@ extern struct cfdriver mmem_cd;
struct dkdriver mmemdkdriver = { mmemstrategy };
static int
mmemmatch(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
mmemmatch(struct device *parent, struct cfdata *cf, void *aux)
{
struct maple_attach_args *ma = aux;
return (ma->ma_function == MAPLE_FN_MEMCARD ? MAPLE_MATCH_FUNC : 0);
return ma->ma_function == MAPLE_FN_MEMCARD ? MAPLE_MATCH_FUNC : 0;
}
static void
mmemattach(parent, self, aux)
struct device *parent, *self;
void *aux;
mmemattach(struct device *parent, struct device *self, void *aux)
{
struct mmem_softc *sc = (void *) self;
struct mmem_softc *sc = (void *)self;
struct maple_attach_args *ma = aux;
int i;
union {
u_int32_t v;
uint32_t v;
struct mmem_funcdef s;
} funcdef;
@ -304,16 +299,14 @@ mmemattach(parent, self, aux)
/*
* get capacity (start from partition 0)
*/
sc->sc_reqm.func_code = htonl(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqm.func_code = htobe32(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqm.pt = 0;
maple_command(sc->sc_parent, sc->sc_unit, MAPLE_FN_MEMCARD,
MAPLE_COMMAND_GETMINFO, sizeof sc->sc_reqm / 4, &sc->sc_reqm, 0);
}
static int
mmemdetach(self, flags)
struct device *self;
int flags;
mmemdetach(struct device *self, int flags)
{
struct mmem_softc *sc = (struct mmem_softc *) self;
struct buf *bp;
@ -370,13 +363,11 @@ mmemdetach(self, flags)
/* fake disklabel */
static void
mmem_defaultlabel(sc, pt, d)
struct mmem_softc *sc;
struct mmem_pt *pt;
struct disklabel *d;
mmem_defaultlabel(struct mmem_softc *sc, struct mmem_pt *pt,
struct disklabel *d)
{
bzero(d, sizeof *d);
memset(d, 0, sizeof *d);
#if 0
d->d_type = DTYPE_FLOPPY; /* XXX? */
@ -402,10 +393,7 @@ mmem_defaultlabel(sc, pt, d)
* called back from maple bus driver
*/
static void
mmem_intr(dev, response, sz, flags)
void *dev;
struct maple_response *response;
int sz, flags;
mmem_intr(void *dev, struct maple_response *response, int sz, int flags)
{
struct mmem_softc *sc = dev;
struct mmem_response_read_data *r = (void *) response->data;
@ -425,7 +413,7 @@ mmem_intr(dev, response, sz, flags)
case MAPLE_RESPONSE_DATATRF:
pt->pt_info = rm->info;
format_bytes(pbuf, sizeof(pbuf),
(u_int64_t)
(uint64_t)
((pt->pt_info.maxblk - pt->pt_info.minblk + 1)
* sc->sc_bsize));
printf("%s: %s, blk %d %d, inf %d, fat %d %d, dir %d %d, icon %d, data %d\n",
@ -450,7 +438,7 @@ mmem_intr(dev, response, sz, flags)
break;
default:
printf("%s: init: unexpected response %#x, sz %d\n",
pt->pt_name, ntohl(response->response_code), sz);
pt->pt_name, be32toh(response->response_code), sz);
break;
}
if (++part == sc->sc_npt) {
@ -461,9 +449,9 @@ mmem_intr(dev, response, sz, flags)
*/
pt = &sc->sc_pt[0];
sc->sc_reqr.func_code =
htonl(MAPLE_FUNC(MAPLE_FN_MEMCARD));
htobe32(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqr.pt = 0;
sc->sc_reqr.block = htons(pt->pt_info.minblk);
sc->sc_reqr.block = htobe16(pt->pt_info.minblk);
sc->sc_reqr.phase = 0;
maple_command(sc->sc_parent, sc->sc_unit,
MAPLE_FN_MEMCARD, MAPLE_COMMAND_BREAD,
@ -491,7 +479,8 @@ mmem_intr(dev, response, sz, flags)
switch ((maple_response_t) response->response_code) {
case MAPLE_RESPONSE_DATATRF: /* read done */
off = sc->sc_raccsz * sc->sc_reqr.phase;
bcopy(r->data + off, sc->sc_iobuf + off, sc->sc_raccsz);
memcpy(sc->sc_iobuf + off, r->data + off,
sc->sc_raccsz);
if (++sc->sc_reqr.phase == sc->sc_racc) {
/* all phase done */
@ -513,8 +502,8 @@ mmem_intr(dev, response, sz, flags)
default:
printf("%s: read: unexpected response %#x %#x, sz %d\n",
sc->sc_pt[sc->sc_reqr.pt].pt_name,
ntohl(response->response_code),
ntohl(r->func_code), sz);
be32toh(response->response_code),
be32toh(r->func_code), sz);
mmemstart_bp(sc); /* retry */
break;
}
@ -526,7 +515,7 @@ mmem_intr(dev, response, sz, flags)
switch ((maple_response_t) response->response_code) {
case MAPLE_RESPONSE_DATATRF: /* read done */
off = sc->sc_raccsz * sc->sc_reqr.phase;
if (bcmp(r->data + off, sc->sc_iobuf + off,
if (memcmp(r->data + off, sc->sc_iobuf + off,
sc->sc_raccsz)) {
/*
* data differ, start writing
@ -554,8 +543,8 @@ mmem_intr(dev, response, sz, flags)
default:
printf("%s: verify: unexpected response %#x %#x, sz %d\n",
sc->sc_pt[sc->sc_reqr.pt].pt_name,
ntohl(response->response_code),
ntohl(r->func_code), sz);
be32toh(response->response_code),
be32toh(r->func_code), sz);
mmemstart_write2(sc); /* start writing */
break;
}
@ -577,9 +566,9 @@ mmem_intr(dev, response, sz, flags)
MAPLE_FLAG_CMD_PERIODIC_TIMING);
} else {
/* go next phase */
bcopy(sc->sc_iobuf
+ sc->sc_waccsz * sc->sc_reqw.phase,
sc->sc_reqw.data, sc->sc_waccsz);
memcpy(sc->sc_reqw.data, sc->sc_iobuf +
sc->sc_waccsz * sc->sc_reqw.phase,
sc->sc_waccsz);
maple_command(sc->sc_parent, sc->sc_unit,
MAPLE_FN_MEMCARD, MAPLE_COMMAND_BWRITE,
MMEM_SIZE_REQW(sc) / 4, &sc->sc_reqw,
@ -595,8 +584,8 @@ mmem_intr(dev, response, sz, flags)
default:
printf("%s: write: unexpected response %#x, %#x, sz %d\n",
sc->sc_pt[sc->sc_reqw.pt].pt_name,
ntohl(response->response_code),
ntohl(r->func_code), sz);
be32toh(response->response_code),
be32toh(r->func_code), sz);
mmemstart_write2(sc); /* retry writing */
break;
}
@ -608,11 +597,7 @@ mmem_intr(dev, response, sz, flags)
}
static void
mmem_printerror(head, rd, blk, code)
const char *head;
int rd; /* 1: read, 0: write */
int blk;
u_int32_t code;
mmem_printerror(const char *head, int rd, int blk, uint32_t code)
{
printf("%s: error %sing blk %d:", head, rd? "read" : "writ", blk);
@ -635,10 +620,7 @@ mmem_printerror(head, rd, blk, code)
}
int
mmemopen(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
mmemopen(dev_t dev, int flags, int devtype, struct proc *p)
{
int diskunit, unit, part, labelpart;
struct mmem_softc *sc;
@ -667,10 +649,7 @@ mmemopen(dev, flags, devtype, p)
}
int
mmemclose(dev, flags, devtype, p)
dev_t dev;
int flags, devtype;
struct proc *p;
mmemclose(dev_t dev, int flags, int devtype, struct proc *p)
{
int diskunit, unit, part, labelpart;
struct mmem_softc *sc;
@ -696,8 +675,7 @@ mmemclose(dev, flags, devtype, p)
}
void
mmemstrategy(bp)
struct buf *bp;
mmemstrategy(struct buf *bp)
{
int diskunit, unit, part, labelpart;
struct mmem_softc *sc;
@ -777,8 +755,7 @@ done: bp->b_resid = bp->b_bcount;
* start I/O operations
*/
static void
mmemstart(sc)
struct mmem_softc *sc;
mmemstart(struct mmem_softc *sc)
{
struct buf *bp;
struct mmem_pt *pt;
@ -816,8 +793,7 @@ mmemstart(sc)
* start/retry a specified I/O operation
*/
static void
mmemstart_bp(sc)
struct mmem_softc *sc;
mmemstart_bp(struct mmem_softc *sc)
{
struct buf *bp;
int diskunit, part;
@ -840,17 +816,16 @@ mmemstart_bp(sc)
*/
/* start read */
sc->sc_stat = (bp->b_flags & B_READ) ? MMEM_READ : MMEM_WRITE1;
sc->sc_reqr.func_code = htonl(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqr.func_code = htobe32(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqr.pt = part;
sc->sc_reqr.block = htons(bp->b_rawblkno);
sc->sc_reqr.block = htobe16(bp->b_rawblkno);
sc->sc_reqr.phase = 0; /* first phase */
maple_command(sc->sc_parent, sc->sc_unit, MAPLE_FN_MEMCARD,
MAPLE_COMMAND_BREAD, sizeof sc->sc_reqr / 4, &sc->sc_reqr, 0);
}
static void
mmemstart_write2(sc)
struct mmem_softc *sc;
mmemstart_write2(struct mmem_softc *sc)
{
struct buf *bp;
int diskunit, part;
@ -873,22 +848,19 @@ mmemstart_write2(sc)
*/
/* start write */
sc->sc_stat = MMEM_WRITE2;
sc->sc_reqw.func_code = htonl(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqw.func_code = htobe32(MAPLE_FUNC(MAPLE_FN_MEMCARD));
sc->sc_reqw.pt = part;
sc->sc_reqw.block = htons(bp->b_rawblkno);
sc->sc_reqw.block = htobe16(bp->b_rawblkno);
sc->sc_reqw.phase = 0; /* first phase */
bcopy(sc->sc_iobuf /* + sc->sc_waccsz * phase */,
sc->sc_reqw.data, sc->sc_waccsz);
memcpy(sc->sc_reqw.data, sc->sc_iobuf /* + sc->sc_waccsz * phase */,
sc->sc_waccsz);
maple_command(sc->sc_parent, sc->sc_unit, MAPLE_FN_MEMCARD,
MAPLE_COMMAND_BWRITE, MMEM_SIZE_REQW(sc) / 4, &sc->sc_reqw,
MAPLE_FLAG_CMD_PERIODIC_TIMING);
}
static void
mmemdone(sc, pt, err)
struct mmem_softc *sc;
struct mmem_pt *pt;
int err;
mmemdone(struct mmem_softc *sc, struct mmem_pt *pt, int err)
{
struct buf *bp = sc->sc_bp;
int s;
@ -930,32 +902,21 @@ mmemdone(sc, pt, err)
}
int
mmemread(dev, uio, flags)
dev_t dev;
struct uio *uio;
int flags;
mmemread(dev_t dev, struct uio *uio, int flags)
{
return (physio(mmemstrategy, NULL, dev, B_READ, minphys, uio));
return physio(mmemstrategy, NULL, dev, B_READ, minphys, uio);
}
int
mmemwrite(dev, uio, flags)
dev_t dev;
struct uio *uio;
int flags;
mmemwrite(dev_t dev, struct uio *uio, int flags)
{
return (physio(mmemstrategy, NULL, dev, B_WRITE, minphys, uio));
return physio(mmemstrategy, NULL, dev, B_WRITE, minphys, uio);
}
int
mmemioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
mmemioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
{
int diskunit, unit, part;
struct mmem_softc *sc;