pccardvar.h revision 90964
166200Simp/* $NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $ */ 252506Simp/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 90964 2002-02-20 14:30:46Z shiba $ */ 352506Simp 452506Simp/* 552506Simp * Copyright (c) 1997 Marc Horowitz. All rights reserved. 652506Simp * 752506Simp * Redistribution and use in source and binary forms, with or without 852506Simp * modification, are permitted provided that the following conditions 952506Simp * are met: 1052506Simp * 1. Redistributions of source code must retain the above copyright 1152506Simp * notice, this list of conditions and the following disclaimer. 1252506Simp * 2. Redistributions in binary form must reproduce the above copyright 1352506Simp * notice, this list of conditions and the following disclaimer in the 1452506Simp * documentation and/or other materials provided with the distribution. 1552506Simp * 3. All advertising materials mentioning features or use of this software 1652506Simp * must display the following acknowledgement: 1752506Simp * This product includes software developed by Marc Horowitz. 1852506Simp * 4. The name of the author may not be used to endorse or promote products 1952506Simp * derived from this software without specific prior written permission. 2052506Simp * 2152506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2252506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2352506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2452506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2552506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2652506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2752506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2852506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2952506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3052506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3152506Simp */ 3252506Simp 3352506Simp#include <sys/types.h> 3452506Simp#include <sys/queue.h> 3552506Simp 3652506Simp#include <machine/bus.h> 3774636Simp#include "card_if.h" 3852506Simp 3952506Simpextern int pccard_verbose; 4052506Simp 4152506Simp/* 4252506Simp * Contains information about mapped/allocated i/o spaces. 4352506Simp */ 4452506Simpstruct pccard_io_handle { 4552506Simp bus_space_tag_t iot; /* bus space tag (from chipset) */ 4652506Simp bus_space_handle_t ioh; /* mapped space handle */ 4752506Simp bus_addr_t addr; /* resulting address in bus space */ 4852506Simp bus_size_t size; /* size of i/o space */ 4952506Simp int flags; /* misc. information */ 5054250Simp int width; 5152506Simp}; 5252506Simp 5352506Simp#define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */ 5452506Simp 5552506Simp/* 5652506Simp * Contains information about allocated memory space. 5752506Simp */ 5852506Simpstruct pccard_mem_handle { 5952506Simp bus_space_tag_t memt; /* bus space tag (from chipset) */ 6052506Simp bus_space_handle_t memh; /* mapped space handle */ 6152506Simp bus_addr_t addr; /* resulting address in bus space */ 6252506Simp bus_size_t size; /* size of mem space */ 6352506Simp bus_size_t realsize; /* how much we really allocated */ 6489959Simp long offset; /* mapped Offset on card */ 6589959Simp bus_addr_t cardaddr; /* Absolute address on card */ 6654250Simp int kind; 6752506Simp}; 6852506Simp 6952506Simp/* pccard itself */ 7052506Simp 7152506Simp#define PCCARD_CFE_MWAIT_REQUIRED 0x0001 7252506Simp#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 7352506Simp#define PCCARD_CFE_WP_ACTIVE 0x0004 7452506Simp#define PCCARD_CFE_BVD_ACTIVE 0x0008 7552506Simp#define PCCARD_CFE_IO8 0x0010 7652506Simp#define PCCARD_CFE_IO16 0x0020 7752506Simp#define PCCARD_CFE_IRQSHARE 0x0040 7852506Simp#define PCCARD_CFE_IRQPULSE 0x0080 7952506Simp#define PCCARD_CFE_IRQLEVEL 0x0100 8052506Simp#define PCCARD_CFE_POWERDOWN 0x0200 8152506Simp#define PCCARD_CFE_READONLY 0x0400 8252506Simp#define PCCARD_CFE_AUDIO 0x0800 8352506Simp 8452506Simpstruct pccard_config_entry { 8552506Simp int number; 8652506Simp u_int32_t flags; 8752506Simp int iftype; 8852506Simp int num_iospace; 8952506Simp 9052506Simp /* 9152506Simp * The card will only decode this mask in any case, so we can 9252506Simp * do dynamic allocation with this in mind, in case the suggestions 9352506Simp * below are no good. 9452506Simp */ 9552506Simp u_long iomask; 9652506Simp struct { 9752506Simp u_long length; 9852506Simp u_long start; 9952506Simp } iospace[4]; /* XXX this could be as high as 16 */ 10052506Simp u_int16_t irqmask; 10152506Simp int num_memspace; 10252506Simp struct { 10352506Simp u_long length; 10452506Simp u_long cardaddr; 10552506Simp u_long hostaddr; 10652506Simp } memspace[2]; /* XXX this could be as high as 8 */ 10752506Simp int maxtwins; 10867187Simp struct resource *iores[4]; 10967187Simp int iorid[4]; 11067187Simp struct resource *irqres; 11167187Simp int irqrid; 11267187Simp struct resource *memres[2]; 11367187Simp int memrid[2]; 11460938Sjake STAILQ_ENTRY(pccard_config_entry) cfe_list; 11552506Simp}; 11652506Simp 11782781Sshibastruct pccard_funce_disk { 11882781Sshiba int pfd_interface; 11982781Sshiba}; 12082781Sshiba 12182781Sshibastruct pccard_funce_lan { 12282781Sshiba int pfl_nidlen; 12382781Sshiba u_int8_t pfl_nid[8]; 12482781Sshiba}; 12582781Sshiba 12682781Sshibaunion pccard_funce { 12782781Sshiba struct pccard_funce_disk pfv_disk; 12882781Sshiba struct pccard_funce_lan pfv_lan; 12982781Sshiba}; 13082781Sshiba 13152506Simpstruct pccard_function { 13252506Simp /* read off the card */ 13352506Simp int number; 13452506Simp int function; 13552506Simp int last_config_index; 13652506Simp u_long ccr_base; 13752506Simp u_long ccr_mask; 13855720Simp struct resource *ccr_res; 13955720Simp int ccr_rid; 14060938Sjake STAILQ_HEAD(, pccard_config_entry) cfe_head; 14160938Sjake STAILQ_ENTRY(pccard_function) pf_list; 14252506Simp /* run-time state */ 14352506Simp struct pccard_softc *sc; 14452506Simp struct pccard_config_entry *cfe; 14552506Simp struct pccard_mem_handle pf_pcmh; 14664927Simp device_t dev; 14752506Simp#define pf_ccrt pf_pcmh.memt 14852506Simp#define pf_ccrh pf_pcmh.memh 14952506Simp#define pf_ccr_realsize pf_pcmh.realsize 15052506Simp bus_addr_t pf_ccr_offset; 15152506Simp int pf_ccr_window; 15252506Simp long pf_mfc_iobase; 15352506Simp long pf_mfc_iomax; 15452506Simp int pf_flags; 15570715Sjon driver_intr_t *intr_handler; 15670715Sjon void *intr_handler_arg; 15770715Sjon void *intr_handler_cookie; 15882781Sshiba 15982781Sshiba union pccard_funce pf_funce; /* CISTPL_FUNCE */ 16082781Sshiba#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface 16182781Sshiba#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid 16282781Sshiba#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen 16352506Simp}; 16452506Simp 16552506Simp/* pf_flags */ 16652506Simp#define PFF_ENABLED 0x0001 /* function is enabled */ 16752506Simp 16852506Simpstruct pccard_card { 16952506Simp int cis1_major; 17052506Simp int cis1_minor; 17152506Simp /* XXX waste of space? */ 17252506Simp char cis1_info_buf[256]; 17352506Simp char *cis1_info[4]; 17452506Simp /* 17552506Simp * Use int32_t for manufacturer and product so that they can 17652506Simp * hold the id value found in card CIS and special value that 17752506Simp * indicates no id was found. 17852506Simp */ 17952506Simp int32_t manufacturer; 18086272Simp#define PCMCIA_VENDOR_INVALID -1 18152506Simp int32_t product; 18286272Simp#define PCMCIA_PRODUCT_INVALID -1 18390964Sshiba int16_t prodext; 18452506Simp u_int16_t error; 18586272Simp#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL } 18660938Sjake STAILQ_HEAD(, pccard_function) pf_head; 18752506Simp}; 18852506Simp 18959389Simp#define PCCARD_MEM_ATTR 1 19059389Simp#define PCCARD_MEM_COMMON 2 19159389Simp 19259389Simp#define PCCARD_WIDTH_AUTO 0 19359389Simp#define PCCARD_WIDTH_IO8 1 19459389Simp#define PCCARD_WIDTH_IO16 2 19559389Simp 19653873Simp/* More later? */ 19753873Simpstruct pccard_ivar { 19853873Simp struct resource_list resources; 19965917Simp struct pccard_function *fcn; 20052506Simp}; 20152506Simp 20252506Simpstruct pccard_softc { 20355720Simp device_t dev; 20452506Simp /* this stuff is for the socket */ 20552506Simp 20652506Simp /* this stuff is for the card */ 20752506Simp struct pccard_card card; 20855500Simp int sc_enabled_count; /* num functions enabled */ 20952506Simp}; 21052506Simp 21152506Simpvoid 21254250Simppccardbus_if_setup(struct pccard_softc*); 21352506Simp 21452506Simpstruct pccard_cis_quirk { 21552506Simp int32_t manufacturer; 21652506Simp int32_t product; 21752506Simp char *cis1_info[4]; 21852506Simp struct pccard_function *pf; 21952506Simp struct pccard_config_entry *cfe; 22052506Simp}; 22152506Simp 22252506Simpstruct pccard_tuple { 22352506Simp unsigned int code; 22452506Simp unsigned int length; 22552506Simp u_long mult; 22652506Simp bus_addr_t ptr; 22752506Simp bus_space_tag_t memt; 22852506Simp bus_space_handle_t memh; 22952506Simp}; 23052506Simp 23166200Simpstruct pccard_product { 23266200Simp const char *pp_name; /* NULL if end of table */ 23366200Simp#define PCCARD_VENDOR_ANY ((u_int32_t) -1) 23466200Simp u_int32_t pp_vendor; 23566200Simp#define PCCARD_PRODUCT_ANY ((u_int32_t) -1) 23666200Simp u_int32_t pp_product; 23766200Simp int pp_expfunc; 23871322Simp const char *pp_cis[4]; 23966200Simp}; 24066200Simp 24166200Simptypedef int (*pccard_product_match_fn) (device_t dev, 24266200Simp const struct pccard_product *ent, int vpfmatch); 24366200Simp 24466200Simpconst struct pccard_product 24566200Simp *pccard_product_lookup(device_t dev, const struct pccard_product *tab, 24666200Simp size_t ent_size, pccard_product_match_fn matchfn); 24766200Simp 24854250Simpvoid pccard_read_cis(struct pccard_softc *); 24952506Simpvoid pccard_check_cis_quirks(device_t); 25052506Simpvoid pccard_print_cis(device_t); 25159193Simpint pccard_scan_cis(device_t, 25259193Simp int (*) (struct pccard_tuple *, void *), void *); 25352506Simp 25452506Simp#define pccard_cis_read_1(tuple, idx0) \ 25552506Simp (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 25652506Simp 25752506Simp#define pccard_tuple_read_1(tuple, idx1) \ 25852506Simp (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 25952506Simp 26052506Simp#define pccard_tuple_read_2(tuple, idx2) \ 26182378Sjon (pccard_tuple_read_1((tuple), (idx2)) | \ 26252506Simp (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 26352506Simp 26452506Simp#define pccard_tuple_read_3(tuple, idx3) \ 26552506Simp (pccard_tuple_read_1((tuple), (idx3)) | \ 26652506Simp (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 26752506Simp (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 26852506Simp 26952506Simp#define pccard_tuple_read_4(tuple, idx4) \ 27052506Simp (pccard_tuple_read_1((tuple), (idx4)) | \ 27152506Simp (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 27252506Simp (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 27352506Simp (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 27452506Simp 27552506Simp#define pccard_tuple_read_n(tuple, n, idxn) \ 27652506Simp (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 27752506Simp (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 27852506Simp (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 27952506Simp /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 28052506Simp 28152506Simp#define PCCARD_SPACE_MEMORY 1 28252506Simp#define PCCARD_SPACE_IO 2 28352506Simp 28452506Simp#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 28552506Simp STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 28652506Simp 28752506Simp#define pccard_io_alloc(pf, start, size, align, pciop) \ 28852506Simp (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 28952506Simp (size), (align), (pciop))) 29052506Simp 29152506Simp#define pccard_io_free(pf, pciohp) \ 29252506Simp (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 29352506Simp 29454250Simpint pccard_io_map(struct pccard_function *, int, bus_addr_t, 29554250Simp bus_size_t, struct pccard_io_handle *, int *); 29654250Simpvoid pccard_io_unmap(struct pccard_function *, int); 29752506Simp 29852506Simp#define pccard_mem_alloc(pf, size, pcmhp) \ 29952506Simp (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 30052506Simp#define pccard_mem_free(pf, pcmhp) \ 30152506Simp (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 30252506Simp#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 30352506Simp (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 30452506Simp (card_addr), (size), (pcmhp), (offsetp), (windowp))) 30552506Simp#define pccard_mem_unmap(pf, window) \ 30652506Simp (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 30756361Shosokawa 30866058Simp/* compat layer */ 30974636Simpstatic __inline int 31074636Simppccard_compat_probe(device_t dev) 31174636Simp{ 31274636Simp return (CARD_COMPAT_DO_PROBE(device_get_parent(dev), dev)); 31374636Simp} 31466058Simp 31574636Simpstatic __inline int 31674636Simppccard_compat_attach(device_t dev) 31774636Simp{ 31874636Simp return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev), dev)); 31974636Simp} 32074636Simp 32156361Shosokawa/* ivar interface */ 32256361Shosokawaenum { 32356361Shosokawa PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 32466200Simp PCCARD_IVAR_VENDOR, 32566200Simp PCCARD_IVAR_PRODUCT, 32690964Sshiba PCCARD_IVAR_PRODEXT, 32766200Simp PCCARD_IVAR_FUNCTION_NUMBER, 32866200Simp PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */ 32966200Simp PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */ 33067167Simp PCCARD_IVAR_CIS3_STR, 33175761Simp PCCARD_IVAR_CIS4_STR, 33275761Simp PCCARD_IVAR_FUNCTION 33356361Shosokawa}; 33456361Shosokawa 33566200Simp#define PCCARD_ACCESSOR(A, B, T) \ 33666200Simp__inline static int \ 33766200Simppccard_get_ ## A(device_t dev, T *t) \ 33866200Simp{ \ 33982378Sjon return BUS_READ_IVAR(device_get_parent(dev), dev, \ 34066200Simp PCCARD_IVAR_ ## B, (uintptr_t *) t); \ 34156361Shosokawa} 34258581Simp 34366200SimpPCCARD_ACCESSOR(ether, ETHADDR, u_int8_t) 34466200SimpPCCARD_ACCESSOR(vendor, VENDOR, u_int32_t) 34566200SimpPCCARD_ACCESSOR(product, PRODUCT, u_int32_t) 34690964SshibaPCCARD_ACCESSOR(prodext, PRODEXT, u_int16_t) 34766200SimpPCCARD_ACCESSOR(function_number,FUNCTION_NUMBER, u_int32_t) 34875761SimpPCCARD_ACCESSOR(function, FUNCTION, u_int32_t) 34966200SimpPCCARD_ACCESSOR(vendor_str, VENDOR_STR, char *) 35066200SimpPCCARD_ACCESSOR(product_str, PRODUCT_STR, char *) 35166200SimpPCCARD_ACCESSOR(cis3_str, CIS3_STR, char *) 35266200Simp 35376387Sdmlb/* shared memory flags */ 35458581Simpenum { 35576387Sdmlb PCCARD_A_MEM_COM, /* common */ 35676387Sdmlb PCCARD_A_MEM_ATTR, /* attribute */ 35776387Sdmlb PCCARD_A_MEM_8BIT, /* 8 bit */ 35876387Sdmlb PCCARD_A_MEM_16BIT /* 16 bit */ 35958581Simp}; 36058581Simp 36164850Simp#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d) 36266847Simp#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d) 36386385Simp 36486385Simp#define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b 36586385Simp#define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b 36686385Simp#define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b 36786385Simp#define PCMCIA_CARD(v, p, f) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \ 36886385Simp PCCARD_P(v, p), f, PCCARD_C(v, p) } 36986385Simp#define PCMCIA_CARD2(v1, p1, p2, f) \ 37086385Simp { PCMCIA_STR_ ## p2, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \ 37186385Simp f, PCMCIA_CIS_ ## p2} 37286385Simp 373