Implement /dev/pccardN.cis. This mirrors the CIS for the card to userland.

pccardc dumpcis /dev/pccardN.cis will work now, but I may rewrite pccardc.

Also, move more of the private data to a new file called pccardvarp.h.
This commit is contained in:
Warner Losh 2005-09-20 06:47:33 +00:00
parent 88750dc361
commit 73cac3387f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=150362
4 changed files with 368 additions and 164 deletions

View File

@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pccard/pccardreg.h>
#include <dev/pccard/pccardvar.h>
#include <dev/pccard/pccardvarp.h>
#include <dev/pccard/pccard_cis.h>
#include "power_if.h"
@ -803,9 +804,12 @@ static int
pccard_attach(device_t dev)
{
struct pccard_softc *sc = PCCARD_SOFTC(dev);
int err;
sc->dev = dev;
sc->sc_enabled_count = 0;
if ((err = pccard_device_create(sc)) != 0)
return (err);
return (bus_generic_attach(dev));
}
@ -813,7 +817,8 @@ static int
pccard_detach(device_t dev)
{
pccard_detach_card(dev);
return 0;
pccard_device_destroy(device_get_softc(dev));
return (0);
}
static int

View File

@ -0,0 +1,169 @@
/*-
* Copyright (c) 2005, M. Warner Losh
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <dev/pccard/pccardreg.h>
#include <dev/pccard/pccardvar.h>
#include <dev/pccard/pccardvarp.h>
#include <dev/pccard/pccard_cis.h>
static d_open_t pccard_open;
static d_close_t pccard_close;
static d_read_t pccard_read;
static d_ioctl_t pccard_ioctl;
static struct cdevsw pccard_cdevsw = {
.d_version = D_VERSION,
.d_open = pccard_open,
.d_close = pccard_close,
.d_read = pccard_read,
.d_ioctl = pccard_ioctl,
.d_name = "pccard"
};
int
pccard_device_create(struct pccard_softc *sc)
{
sc->cisdev = make_dev(&pccard_cdevsw, 0, 0, 0, 0666, "pccard%u.cis",
device_get_unit(sc->dev));
sc->cisdev->si_drv1 = sc;
return (0);
}
int
pccard_device_destroy(struct pccard_softc *sc)
{
destroy_dev(sc->cisdev);
return (0);
}
static int
pccard_build_cis(const struct pccard_tuple *tuple, void *argp)
{
struct cis_buffer *cis;
int i;
uint8_t ch;
cis = (struct cis_buffer *)argp;
/*
* CISTPL_END is a special case, it has no length field.
*/
if (tuple->code == CISTPL_END) {
if (cis->len + 1 > sizeof(cis->buffer))
return (ENOSPC);
cis->buffer[cis->len++] = tuple->code;
return (0);
}
if (cis->len + 2 + tuple->code > sizeof(cis->buffer))
return (ENOSPC);
cis->buffer[cis->len++] = tuple->code;
cis->buffer[cis->len++] = tuple->length;
for (i = 0; i < tuple->length; i++) {
ch = pccard_tuple_read_1(tuple, i);
cis->buffer[cis->len++] = ch;
}
return (0);
}
static int
pccard_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
{
device_t parent, child;
device_t *kids;
int cnt, err;
struct pccard_softc *sc;
sc = dev->si_drv1;
if (sc->cis_open)
return (EBUSY);
parent = sc->dev;
err = device_get_children(parent, &kids, &cnt);
if (err)
return err;
if (cnt == 0) {
free(kids, M_TEMP);
sc->cis_open++;
sc->cis = NULL;
return (0);
}
child = kids[0];
free(kids, M_TEMP);
sc->cis = malloc(sizeof(*sc->cis), M_TEMP, M_ZERO | M_WAITOK);
err = pccard_scan_cis(parent, child, pccard_build_cis, sc->cis);
if (err) {
free(sc->cis, M_TEMP);
sc->cis = NULL;
return (err);
}
sc->cis_open++;
return (0);
}
static int
pccard_close(struct cdev *dev, int fflags, int devtype, struct thread *td)
{
struct pccard_softc *sc;
sc = dev->si_drv1;
free(sc->cis, M_TEMP);
sc->cis = NULL;
sc->cis_open = 0;
return (0);
}
static int
pccard_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
struct thread *td)
{
return (ENOTTY);
}
static int
pccard_read(struct cdev *dev, struct uio *uio, int ioflag)
{
struct pccard_softc *sc;
sc = dev->si_drv1;
/* EOF */
if (sc->cis == NULL || uio->uio_offset > sc->cis->len)
return (0);
return (uiomove(sc->cis->buffer + uio->uio_offset,
MIN(uio->uio_resid, sc->cis->len - uio->uio_offset), uio));
}

View File

@ -30,8 +30,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
extern int pccard_verbose;
/*
* PCCARD_API_LEVEL. When set to 5, we provide a 5.x compatable API
* for driver writers that have to share their code between 5.x and 6.x.
@ -71,153 +69,14 @@ struct pccard_mem_handle {
int kind;
};
/* pccard itself */
#define PCCARD_MEM_PAGE_SIZE 4096
#define PCCARD_CFE_MWAIT_REQUIRED 0x0001
#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002
#define PCCARD_CFE_WP_ACTIVE 0x0004
#define PCCARD_CFE_BVD_ACTIVE 0x0008
#define PCCARD_CFE_IO8 0x0010
#define PCCARD_CFE_IO16 0x0020
#define PCCARD_CFE_IRQSHARE 0x0040
#define PCCARD_CFE_IRQPULSE 0x0080
#define PCCARD_CFE_IRQLEVEL 0x0100
#define PCCARD_CFE_POWERDOWN 0x0200
#define PCCARD_CFE_READONLY 0x0400
#define PCCARD_CFE_AUDIO 0x0800
struct pccard_config_entry {
int number;
uint32_t flags;
int iftype;
int num_iospace;
/*
* The card will only decode this mask in any case, so we can
* do dynamic allocation with this in mind, in case the suggestions
* below are no good.
*/
u_long iomask;
struct {
u_long length;
u_long start;
} iospace[4]; /* XXX this could be as high as 16 */
uint16_t irqmask;
int num_memspace;
struct {
u_long length;
u_long cardaddr;
u_long hostaddr;
} memspace[2]; /* XXX this could be as high as 8 */
int maxtwins;
STAILQ_ENTRY(pccard_config_entry) cfe_list;
};
struct pccard_funce_disk {
int pfd_interface;
};
struct pccard_funce_lan {
int pfl_nidlen;
uint8_t pfl_nid[8];
};
union pccard_funce {
struct pccard_funce_disk pfv_disk;
struct pccard_funce_lan pfv_lan;
};
struct pccard_function {
/* read off the card */
int number;
int function;
int last_config_index;
uint32_t ccr_base; /* Offset with card's memory */
uint32_t ccr_mask;
struct resource *ccr_res;
int ccr_rid;
STAILQ_HEAD(, pccard_config_entry) cfe_head;
STAILQ_ENTRY(pccard_function) pf_list;
/* run-time state */
struct pccard_softc *sc;
struct pccard_config_entry *cfe;
struct pccard_mem_handle pf_pcmh;
device_t dev;
#define pf_ccrt pf_pcmh.memt
#define pf_ccrh pf_pcmh.memh
#define pf_ccr_realsize pf_pcmh.realsize
uint32_t pf_ccr_offset; /* Offset from ccr_base of CIS */
int pf_ccr_window;
bus_addr_t pf_mfc_iobase;
bus_addr_t pf_mfc_iomax;
int pf_flags;
driver_intr_t *intr_handler;
void *intr_handler_arg;
void *intr_handler_cookie;
union pccard_funce pf_funce; /* CISTPL_FUNCE */
#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
};
/* pf_flags */
#define PFF_ENABLED 0x0001 /* function is enabled */
struct pccard_card {
int cis1_major;
int cis1_minor;
/* XXX waste of space? */
char cis1_info_buf[256];
char *cis1_info[4];
/*
* Use int32_t for manufacturer and product so that they can
* hold the id value found in card CIS and special value that
* indicates no id was found.
*/
int32_t manufacturer;
#define PCMCIA_VENDOR_INVALID -1
int32_t product;
#define PCMCIA_PRODUCT_INVALID -1
int16_t prodext;
uint16_t error;
#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
STAILQ_HEAD(, pccard_function) pf_head;
};
#define PCCARD_WIDTH_AUTO 0
#define PCCARD_WIDTH_IO8 1
#define PCCARD_WIDTH_IO16 2
/* More later? */
struct pccard_ivar {
struct resource_list resources;
struct pccard_function *pf;
};
struct pccard_softc {
device_t dev;
/* this stuff is for the socket */
/* this stuff is for the card */
struct pccard_card card;
int sc_enabled_count; /* num functions enabled */
};
struct pccard_cis_quirk {
int32_t manufacturer;
int32_t product;
char *cis1_info[4];
struct pccard_function *pf;
struct pccard_config_entry *cfe;
};
struct pccard_tuple {
unsigned int code;
unsigned int length;
u_long mult;
u_long mult; /* dist btn successive bytes */
bus_addr_t ptr;
bus_space_tag_t memt;
bus_space_handle_t memh;
@ -251,11 +110,6 @@ pccard_product_lookup(device_t dev, const struct pccard_product *tab,
tab, ent_size, matchfn);
}
void pccard_read_cis(struct pccard_softc *);
void pccard_check_cis_quirks(device_t);
void pccard_print_cis(device_t);
int pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
#define pccard_cis_read_1(tuple, idx0) \
(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
@ -290,19 +144,6 @@ int pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
(STAILQ_FIRST(&(sc)->card.pf_head) && \
STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list))
/* compat layer */
static __inline int
pccard_compat_probe(device_t dev)
{
return (CARD_COMPAT_DO_PROBE(device_get_parent(dev), dev));
}
static __inline int
pccard_compat_attach(device_t dev)
{
return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev), dev));
}
/* Convenience functions */
static __inline int
@ -376,9 +217,6 @@ enum {
PCCARD_A_MEM_16BIT /* 16 bit */
};
#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
#define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b
#define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b
#define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b

192
sys/dev/pccard/pccardvarp.h Normal file
View File

@ -0,0 +1,192 @@
/*-
* Copyright (c) 2005, M. Warner Losh
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _PCCARD_PCCARDVARP_H
#define _PCCARD_PCCARDVARP_H
/* pccard itself */
#define PCCARD_MEM_PAGE_SIZE 4096
#define PCCARD_CFE_MWAIT_REQUIRED 0x0001
#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002
#define PCCARD_CFE_WP_ACTIVE 0x0004
#define PCCARD_CFE_BVD_ACTIVE 0x0008
#define PCCARD_CFE_IO8 0x0010
#define PCCARD_CFE_IO16 0x0020
#define PCCARD_CFE_IRQSHARE 0x0040
#define PCCARD_CFE_IRQPULSE 0x0080
#define PCCARD_CFE_IRQLEVEL 0x0100
#define PCCARD_CFE_POWERDOWN 0x0200
#define PCCARD_CFE_READONLY 0x0400
#define PCCARD_CFE_AUDIO 0x0800
struct pccard_config_entry {
int number;
uint32_t flags;
int iftype;
int num_iospace;
/*
* The card will only decode this mask in any case, so we can
* do dynamic allocation with this in mind, in case the suggestions
* below are no good.
*/
u_long iomask;
struct {
u_long length;
u_long start;
} iospace[4]; /* XXX this could be as high as 16 */
uint16_t irqmask;
int num_memspace;
struct {
u_long length;
u_long cardaddr;
u_long hostaddr;
} memspace[2]; /* XXX this could be as high as 8 */
int maxtwins;
STAILQ_ENTRY(pccard_config_entry) cfe_list;
};
struct pccard_funce_disk {
int pfd_interface;
};
struct pccard_funce_lan {
int pfl_nidlen;
uint8_t pfl_nid[8];
};
union pccard_funce {
struct pccard_funce_disk pfv_disk;
struct pccard_funce_lan pfv_lan;
};
struct pccard_function {
/* read off the card */
int number;
int function;
int last_config_index;
uint32_t ccr_base; /* Offset with card's memory */
uint32_t ccr_mask;
struct resource *ccr_res;
int ccr_rid;
STAILQ_HEAD(, pccard_config_entry) cfe_head;
STAILQ_ENTRY(pccard_function) pf_list;
/* run-time state */
struct pccard_softc *sc;
struct pccard_config_entry *cfe;
struct pccard_mem_handle pf_pcmh;
device_t dev;
#define pf_ccrt pf_pcmh.memt
#define pf_ccrh pf_pcmh.memh
#define pf_ccr_realsize pf_pcmh.realsize
uint32_t pf_ccr_offset; /* Offset from ccr_base of CIS */
int pf_ccr_window;
bus_addr_t pf_mfc_iobase;
bus_addr_t pf_mfc_iomax;
int pf_flags;
driver_intr_t *intr_handler;
void *intr_handler_arg;
void *intr_handler_cookie;
union pccard_funce pf_funce; /* CISTPL_FUNCE */
#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
};
/* pf_flags */
#define PFF_ENABLED 0x0001 /* function is enabled */
struct pccard_card {
int cis1_major;
int cis1_minor;
/* XXX waste of space? */
char cis1_info_buf[256];
char *cis1_info[4];
/*
* Use int32_t for manufacturer and product so that they can
* hold the id value found in card CIS and special value that
* indicates no id was found.
*/
int32_t manufacturer;
#define PCMCIA_VENDOR_INVALID -1
int32_t product;
#define PCMCIA_PRODUCT_INVALID -1
int16_t prodext;
uint16_t error;
#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
STAILQ_HEAD(, pccard_function) pf_head;
};
/* More later? */
struct pccard_ivar {
struct resource_list resources;
struct pccard_function *pf;
};
struct cis_buffer
{
size_t len; /* Actual length of the CIS */
uint8_t buffer[2040]; /* small enough to be 2k */
};
struct pccard_softc {
device_t dev;
/* this stuff is for the socket */
/* this stuff is for the card */
struct pccard_card card;
int sc_enabled_count; /* num functions enabled */
struct cdev *cisdev;
int cis_open;
struct cis_buffer *cis;
};
struct pccard_cis_quirk {
int32_t manufacturer;
int32_t product;
char *cis1_info[4];
struct pccard_function *pf;
struct pccard_config_entry *cfe;
};
void pccard_read_cis(struct pccard_softc *);
void pccard_check_cis_quirks(device_t);
void pccard_print_cis(device_t);
int pccard_scan_cis(device_t, device_t, pccard_scan_t, void *);
int pccard_device_create(struct pccard_softc *);
int pccard_device_destroy(struct pccard_softc *);
#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d)
#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d)
#endif /* _PCCARD_PCCARDVARP_H */