#include <sys/types.h>
#include <sys/queue.h>
#include <machine/bus.h>
#include <dev/pcmcia/pcmciachip.h>
extern int pcmcia_verbose;
struct pcmcia_io_handle {
bus_space_tag_t iot;
bus_space_handle_t ioh;
bus_addr_t addr;
bus_size_t size;
int flags;
};
#define PCMCIA_IO_ALLOCATED 0x01
struct pcmcia_mem_handle {
bus_space_tag_t memt;
bus_space_handle_t memh;
bus_addr_t addr;
bus_size_t size;
pcmcia_mem_handle_t mhandle;
bus_size_t realsize;
};
#define PCMCIA_CFE_MWAIT_REQUIRED 0x0001
#define PCMCIA_CFE_RDYBSY_ACTIVE 0x0002
#define PCMCIA_CFE_WP_ACTIVE 0x0004
#define PCMCIA_CFE_BVD_ACTIVE 0x0008
#define PCMCIA_CFE_IO8 0x0010
#define PCMCIA_CFE_IO16 0x0020
#define PCMCIA_CFE_IRQSHARE 0x0040
#define PCMCIA_CFE_IRQPULSE 0x0080
#define PCMCIA_CFE_IRQLEVEL 0x0100
#define PCMCIA_CFE_POWERDOWN 0x0200
#define PCMCIA_CFE_READONLY 0x0400
#define PCMCIA_CFE_AUDIO 0x0800
struct pcmcia_config_entry {
int number;
u_int32_t flags;
int iftype;
int num_iospace;
u_long iomask;
struct {
u_long length;
u_long start;
} iospace[4];
u_int16_t irqmask;
int num_memspace;
struct {
u_long length;
u_long cardaddr;
u_long hostaddr;
} memspace[2];
int maxtwins;
SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
};
struct pcmcia_function {
int number;
int function;
int last_config_index;
u_long ccr_base;
u_long ccr_mask;
SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
SIMPLEQ_ENTRY(pcmcia_function) pf_list;
struct pcmcia_softc *sc;
struct device *child;
struct pcmcia_config_entry *cfe;
struct pcmcia_mem_handle pf_pcmh;
#define pf_ccrt pf_pcmh.memt
#define pf_ccrh pf_pcmh.memh
#define pf_ccr_mhandle pf_pcmh.mhandle
#define pf_ccr_realsize pf_pcmh.realsize
bus_size_t pf_ccr_offset;
int pf_ccr_window;
bus_addr_t pf_mfc_iobase;
bus_addr_t pf_mfc_iomax;
int (*ih_fct)(void *);
void *ih_arg;
int ih_ipl;
int pf_flags;
};
#define PFF_ENABLED 0x0001
#define PFF_FAKE 0x0002
struct pcmcia_card {
int cis1_major;
int cis1_minor;
char cis1_info_buf[256];
char *cis1_info[4];
u_int16_t manufacturer;
#define PCMCIA_VENDOR_INVALID 0xffff
u_int16_t product;
#define PCMCIA_PRODUCT_INVALID 0xffff
u_int16_t error;
#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL }
SIMPLEQ_HEAD(, pcmcia_function) pf_head;
};
struct pcmcia_softc {
struct device dev;
pcmcia_chipset_tag_t pct;
pcmcia_chipset_handle_t pch;
struct pcmcia_card card;
void *ih;
int sc_enabled_count;
bus_addr_t iobase;
bus_size_t iosize;
};
struct pcmcia_cis_quirk {
u_int16_t manufacturer;
u_int16_t product;
char *cis1_info[4];
struct pcmcia_function *pf;
struct pcmcia_config_entry *cfe;
};
struct pcmcia_attach_args {
u_int16_t manufacturer;
u_int16_t product;
struct pcmcia_card *card;
struct pcmcia_function *pf;
};
struct pcmcia_tuple {
unsigned int code;
unsigned int length;
unsigned int addrshift;
unsigned int flags;
#define PTF_INDIRECT 0x01
bus_size_t indirect_ptr;
bus_size_t ptr;
bus_space_tag_t memt;
bus_space_handle_t memh;
};
void pcmcia_read_cis(struct pcmcia_softc *);
void pcmcia_check_cis_quirks(struct pcmcia_softc *);
void pcmcia_print_cis(struct pcmcia_softc *);
int pcmcia_scan_cis(struct device * dev,
int (*) (struct pcmcia_tuple *, void *), void *);
uint8_t pcmcia_cis_read_1(struct pcmcia_tuple *, bus_size_t);
#define pcmcia_tuple_read_1(tuple, idx1) \
(pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
#define pcmcia_tuple_read_2(tuple, idx2) \
(pcmcia_tuple_read_1((tuple), (idx2)) | \
(pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
#define pcmcia_tuple_read_3(tuple, idx3) \
(pcmcia_tuple_read_1((tuple), (idx3)) | \
(pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
(pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
#define pcmcia_tuple_read_4(tuple, idx4) \
(pcmcia_tuple_read_1((tuple), (idx4)) | \
(pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
(pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
(pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
#define pcmcia_tuple_read_n(tuple, n, idxn) \
(((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) : \
(((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) : \
(((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) : \
pcmcia_tuple_read_4((tuple), (idxn)))))
#define PCMCIA_SPACE_MEMORY 1
#define PCMCIA_SPACE_IO 2
int pcmcia_ccr_read(struct pcmcia_function *, int);
void pcmcia_ccr_write(struct pcmcia_function *, int, int);
#define pcmcia_mfc(sc) (SIMPLEQ_FIRST(&(sc)->card.pf_head) && \
SIMPLEQ_NEXT(SIMPLEQ_FIRST(&(sc)->card.pf_head), pf_list))
void pcmcia_function_init(struct pcmcia_function *,
struct pcmcia_config_entry *);
int pcmcia_function_enable(struct pcmcia_function *);
void pcmcia_function_disable(struct pcmcia_function *);
#define pcmcia_io_alloc(pf, start, size, align, pciop) \
(pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \
(size), (align), (pciop)))
int pcmcia_io_map(struct pcmcia_function *, int, bus_addr_t,
bus_size_t, struct pcmcia_io_handle *, int *);
#define pcmcia_io_unmap(pf, window) \
(pcmcia_chip_io_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
#define pcmcia_io_free(pf, pciop) \
(pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciop)))
#define pcmcia_mem_alloc(pf, size, pcmhp) \
(pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
#define pcmcia_mem_free(pf, pcmhp) \
(pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
#define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
(pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \
(card_addr), (size), (pcmhp), (offsetp), (windowp)))
#define pcmcia_mem_unmap(pf, window) \
(pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
void *pcmcia_intr_establish(struct pcmcia_function *, int,
int (*) (void *), void *, char *);
void pcmcia_intr_disestablish(struct pcmcia_function *, void *);
const char *pcmcia_intr_string(struct pcmcia_function *, void *);