Home | History | Annotate | Line # | Download | only in cardbus
cardbus.c revision 1.10
      1  1.10      joda /*	$NetBSD: cardbus.c,v 1.10 1999/11/08 20:19:10 joda Exp $	*/
      2   1.1      haya 
      3   1.1      haya /*
      4   1.4      haya  * Copyright (c) 1997, 1998 and 1999
      5   1.4      haya  *     HAYAKAWA Koichi.  All rights reserved.
      6   1.1      haya  *
      7   1.1      haya  * Redistribution and use in source and binary forms, with or without
      8   1.1      haya  * modification, are permitted provided that the following conditions
      9   1.1      haya  * are met:
     10   1.1      haya  * 1. Redistributions of source code must retain the above copyright
     11   1.1      haya  *    notice, this list of conditions and the following disclaimer.
     12   1.1      haya  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      haya  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      haya  *    documentation and/or other materials provided with the distribution.
     15   1.1      haya  * 3. All advertising materials mentioning features or use of this software
     16   1.1      haya  *    must display the following acknowledgement:
     17   1.1      haya  *	This product includes software developed by HAYAKAWA Koichi.
     18   1.1      haya  * 4. The name of the author may not be used to endorse or promote products
     19   1.1      haya  *    derived from this software without specific prior written permission.
     20   1.1      haya  *
     21   1.1      haya  *
     22   1.1      haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1      haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24   1.1      haya  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25   1.1      haya  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     26   1.1      haya  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27   1.1      haya  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28   1.1      haya  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1      haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     30   1.1      haya  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     31   1.1      haya  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32   1.1      haya  * POSSIBILITY OF SUCH DAMAGE.
     33   1.1      haya  */
     34   1.1      haya 
     35   1.4      haya #include "opt_cardbus.h"
     36   1.1      haya 
     37   1.1      haya #include <sys/types.h>
     38   1.1      haya #include <sys/param.h>
     39   1.1      haya #include <sys/systm.h>
     40   1.1      haya #include <sys/device.h>
     41   1.1      haya #include <sys/malloc.h>
     42   1.1      haya #include <sys/kernel.h>
     43   1.1      haya #include <sys/syslog.h>
     44   1.1      haya 
     45   1.1      haya #include <machine/bus.h>
     46   1.1      haya 
     47   1.1      haya #include <dev/cardbus/cardbusvar.h>
     48   1.1      haya #include <dev/cardbus/pccardcis.h>
     49   1.1      haya 
     50   1.7      joda #include <dev/cardbus/cardbus_exrom.h>
     51   1.7      joda 
     52   1.1      haya #include <dev/pci/pcivar.h>	/* XXX */
     53   1.1      haya #include <dev/pci/pcireg.h>	/* XXX */
     54   1.1      haya 
     55  1.10      joda #include <dev/pcmcia/pcmciareg.h> /* XXX */
     56  1.10      joda 
     57   1.1      haya #if defined CARDBUS_DEBUG
     58   1.1      haya #define STATIC
     59   1.1      haya #define DPRINTF(a) printf a
     60   1.1      haya #define DDELAY(x) delay((x)*1000*1000)
     61   1.1      haya #else
     62   1.1      haya #define STATIC static
     63   1.1      haya #define DPRINTF(a)
     64   1.1      haya #endif
     65   1.1      haya 
     66   1.1      haya 
     67   1.1      haya 
     68   1.1      haya STATIC void cardbusattach __P((struct device *, struct device *, void *));
     69   1.1      haya /* STATIC int cardbusprint __P((void *, const char *)); */
     70   1.1      haya int cardbus_attach_card __P((struct cardbus_softc *));
     71   1.1      haya 
     72   1.1      haya #if !defined __BROKEN_INDIRECT_CONFIG
     73   1.1      haya STATIC int cardbusmatch __P((struct device *, struct cfdata *, void *));
     74   1.1      haya static int cardbussubmatch __P((struct device *, struct cfdata *, void *));
     75   1.1      haya #else
     76   1.1      haya STATIC int cardbusmatch __P((struct device *, void *, void *));
     77   1.1      haya static int cardbussubmatch __P((struct device *, void *, void *));
     78   1.1      haya #endif
     79   1.1      haya static int cardbusprint __P((void *, const char *));
     80   1.1      haya 
     81  1.10      joda typedef void (*tuple_decode_func)(u_int8_t*, int, void*);
     82  1.10      joda 
     83  1.10      joda static int decode_tuples __P((u_int8_t *, int, tuple_decode_func, void*));
     84  1.10      joda #ifdef CARDBUS_DEBUG
     85  1.10      joda static void print_tuple __P((u_int8_t*, int, void*));
     86  1.10      joda #endif
     87   1.1      haya 
     88   1.7      joda static int cardbus_read_tuples __P((struct cardbus_attach_args *,
     89   1.7      joda 				    cardbusreg_t, u_int8_t *, size_t));
     90   1.7      joda 
     91   1.8      joda static void enable_function __P((struct cardbus_softc *, int, int));
     92   1.8      joda static void disable_function __P((struct cardbus_softc *, int));
     93   1.8      joda 
     94   1.1      haya 
     95   1.1      haya struct cfattach cardbus_ca = {
     96   1.1      haya 	sizeof(struct cardbus_softc), cardbusmatch, cardbusattach
     97   1.1      haya };
     98   1.1      haya 
     99   1.1      haya #ifndef __NetBSD_Version__
    100   1.1      haya struct cfdriver cardbus_cd = {
    101   1.1      haya 	NULL, "cardbus", DV_DULL
    102   1.1      haya };
    103   1.1      haya #endif
    104   1.1      haya 
    105   1.1      haya 
    106   1.1      haya STATIC int
    107   1.1      haya #if defined __BROKEN_INDIRECT_CONFIG
    108   1.1      haya cardbusmatch(parent, match, aux)
    109   1.1      haya      struct device *parent;
    110   1.1      haya      void *match;
    111   1.1      haya      void *aux;
    112   1.1      haya #else
    113   1.1      haya cardbusmatch(parent, cf, aux)
    114   1.1      haya      struct device *parent;
    115   1.1      haya      struct cfdata *cf;
    116   1.1      haya      void *aux;
    117   1.1      haya #endif
    118   1.1      haya {
    119   1.1      haya #if defined __BROKEN_INDIRECT_CONFIG
    120   1.1      haya   struct cfdata *cf = match;
    121   1.1      haya #endif
    122   1.1      haya   struct cbslot_attach_args *cba = aux;
    123   1.1      haya 
    124   1.1      haya   if (strcmp(cba->cba_busname, cf->cf_driver->cd_name)) {
    125   1.1      haya     DPRINTF(("cardbusmatch: busname differs %s <=> %s\n",
    126   1.1      haya 	     cba->cba_busname, cf->cf_driver->cd_name));
    127   1.1      haya     return 0;
    128   1.1      haya   }
    129   1.1      haya 
    130   1.6      haya #if 0
    131   1.1      haya   /* which function? */
    132   1.1      haya   if (cf->cbslotcf_func != CBSLOT_UNK_FUNC &&
    133   1.1      haya       cf->cbslotcf_func != cba->cba_function) {
    134   1.6      haya     DPRINTF(("cardbusmatch: function differs %d <=> %d\n",
    135   1.1      haya 	     cf->cbslotcf_func, cba->cba_function));
    136   1.1      haya     return 0;
    137   1.1      haya   }
    138   1.6      haya #endif
    139   1.1      haya 
    140   1.1      haya   if (cba->cba_function < 0 || cba->cba_function > 255) {
    141   1.1      haya     return 0;
    142   1.1      haya   }
    143   1.1      haya 
    144   1.1      haya   return 1;
    145   1.1      haya }
    146   1.1      haya 
    147   1.1      haya 
    148   1.1      haya 
    149   1.1      haya STATIC void
    150   1.1      haya cardbusattach(parent, self, aux)
    151   1.1      haya      struct device *parent;
    152   1.1      haya      struct device *self;
    153   1.1      haya      void *aux;
    154   1.1      haya {
    155   1.1      haya   struct cardbus_softc *sc = (void *)self;
    156   1.1      haya   struct cbslot_attach_args *cba = aux;
    157   1.1      haya   int cdstatus;
    158   1.1      haya 
    159   1.1      haya   sc->sc_bus = cba->cba_bus;
    160   1.1      haya   sc->sc_device = cba->cba_function;
    161   1.1      haya   sc->sc_intrline = cba->cba_intrline;
    162   1.1      haya   sc->sc_cacheline = cba->cba_cacheline;
    163   1.1      haya   sc->sc_lattimer = cba->cba_lattimer;
    164   1.1      haya 
    165   1.3  augustss   printf(": bus %d device %d", sc->sc_bus, sc->sc_device);
    166   1.3  augustss   printf(" cacheline 0x%x, lattimer 0x%x\n", sc->sc_cacheline,sc->sc_lattimer);
    167   1.1      haya 
    168   1.1      haya   sc->sc_iot = cba->cba_iot;	/* CardBus I/O space tag */
    169   1.1      haya   sc->sc_memt = cba->cba_memt;	/* CardBus MEM space tag */
    170   1.1      haya   sc->sc_dmat = cba->cba_dmat;	/* DMA tag */
    171   1.1      haya   sc->sc_cc = cba->cba_cc;
    172   1.1      haya   sc->sc_cf = cba->cba_cf;
    173   1.1      haya 
    174   1.1      haya #if rbus
    175   1.1      haya   sc->sc_rbus_iot = cba->cba_rbus_iot;
    176   1.1      haya   sc->sc_rbus_memt = cba->cba_rbus_memt;
    177   1.1      haya #endif
    178   1.1      haya 
    179   1.1      haya   sc->sc_funcs = NULL;
    180   1.1      haya 
    181   1.1      haya   cdstatus = 0;
    182   1.1      haya }
    183   1.1      haya 
    184   1.7      joda static int
    185   1.7      joda cardbus_read_tuples(ca, cis_ptr, tuples, len)
    186   1.7      joda      struct cardbus_attach_args *ca;
    187   1.7      joda      cardbusreg_t cis_ptr;
    188   1.7      joda      u_int8_t *tuples;
    189   1.7      joda      size_t len;
    190   1.7      joda {
    191   1.8      joda     struct cardbus_softc *sc = ca->ca_ct->ct_sc;
    192   1.7      joda     cardbus_chipset_tag_t cc = ca->ca_ct->ct_cc;
    193   1.7      joda     cardbus_function_tag_t cf = ca->ca_ct->ct_cf;
    194   1.7      joda     cardbustag_t tag = ca->ca_tag;
    195   1.7      joda     cardbusreg_t command;
    196   1.7      joda     int found = 0;
    197   1.7      joda 
    198   1.7      joda     int i, j;
    199   1.7      joda     int cardbus_space = cis_ptr & CARDBUS_CIS_ASIMASK;
    200   1.7      joda     bus_space_handle_t bar_memh;
    201   1.7      joda     bus_size_t bar_size;
    202   1.7      joda     bus_addr_t bar_addr;
    203   1.7      joda 
    204   1.7      joda     int reg;
    205   1.7      joda 
    206   1.7      joda     memset(tuples, 0, len);
    207   1.7      joda 
    208   1.7      joda     cis_ptr = cis_ptr & CARDBUS_CIS_ADDRMASK;
    209   1.7      joda 
    210   1.7      joda     switch(cardbus_space) {
    211   1.7      joda     case CARDBUS_CIS_ASI_TUPLE:
    212   1.8      joda 	DPRINTF(("%s: reading CIS data from configuration space\n",
    213   1.8      joda 		 sc->sc_dev.dv_xname));
    214   1.7      joda 	for (i = cis_ptr, j = 0; i < 0xff; i += 4) {
    215   1.7      joda 	    u_int32_t e = (cf->cardbus_conf_read)(cc, tag, i);
    216   1.7      joda 	    tuples[j] = 0xff & e;
    217   1.7      joda 	    e >>= 8;
    218   1.7      joda 	    tuples[j + 1] = 0xff & e;
    219   1.7      joda 	    e >>= 8;
    220   1.7      joda 	    tuples[j + 2] = 0xff & e;
    221   1.7      joda 	    e >>= 8;
    222   1.7      joda 	    tuples[j + 3] = 0xff & e;
    223   1.7      joda 	    j += 4;
    224   1.7      joda 	}
    225   1.7      joda 	found++;
    226   1.7      joda 	break;
    227   1.1      haya 
    228   1.7      joda     case CARDBUS_CIS_ASI_BAR0:
    229   1.7      joda     case CARDBUS_CIS_ASI_BAR1:
    230   1.7      joda     case CARDBUS_CIS_ASI_BAR2:
    231   1.7      joda     case CARDBUS_CIS_ASI_BAR3:
    232   1.7      joda     case CARDBUS_CIS_ASI_BAR4:
    233   1.7      joda     case CARDBUS_CIS_ASI_BAR5:
    234   1.7      joda     case CARDBUS_CIS_ASI_ROM:
    235   1.7      joda 	if(cardbus_space == CARDBUS_CIS_ASI_ROM) {
    236   1.7      joda 	    reg = CARDBUS_ROM_REG;
    237   1.8      joda 	    DPRINTF(("%s: reading CIS data from ROM\n",
    238   1.8      joda 		     sc->sc_dev.dv_xname));
    239   1.7      joda 	} else {
    240   1.7      joda 	    reg = CARDBUS_BASE0_REG + (cardbus_space - 1) * 4;
    241   1.7      joda 	    DPRINTF(("%s: reading CIS data from BAR%d\n",
    242   1.8      joda 		     sc->sc_dev.dv_xname, cardbus_space - 1));
    243   1.7      joda 	}
    244   1.7      joda 
    245   1.7      joda 	/* XXX zero register so mapreg_map doesn't get confused by old
    246   1.7      joda            contents */
    247   1.7      joda 	cardbus_conf_write(cc, cf, tag, reg, 0);
    248   1.7      joda 	if(Cardbus_mapreg_map(ca->ca_ct, reg,
    249   1.7      joda 			      CARDBUS_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    250   1.7      joda 			      0,
    251   1.7      joda 			      NULL, &bar_memh, &bar_addr, &bar_size)) {
    252   1.8      joda 	    printf("%s: failed to map memory\n", sc->sc_dev.dv_xname);
    253   1.7      joda 	    return 1;
    254   1.7      joda 	}
    255   1.7      joda 
    256   1.7      joda 
    257   1.7      joda 	if(cardbus_space == CARDBUS_CIS_ASI_ROM) {
    258   1.7      joda 	    cardbusreg_t exrom;
    259   1.7      joda 	    int save;
    260   1.7      joda 	    struct cardbus_rom_image_head rom_image;
    261   1.7      joda 	    struct cardbus_rom_image *p;
    262   1.7      joda 
    263   1.7      joda 	    save = splhigh();
    264   1.7      joda 	    /* enable rom address decoder */
    265   1.7      joda 	    exrom = cardbus_conf_read(cc, cf, tag, reg);
    266   1.7      joda 	    cardbus_conf_write(cc, cf, tag, reg, exrom | 1);
    267   1.7      joda 
    268   1.7      joda 	    command = cardbus_conf_read(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG);
    269   1.7      joda 	    cardbus_conf_write(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG,
    270   1.7      joda 			       command | CARDBUS_COMMAND_MEM_ENABLE);
    271   1.7      joda 
    272   1.7      joda 	    if(cardbus_read_exrom(ca->ca_memt, bar_memh, &rom_image))
    273   1.7      joda 		goto out;
    274   1.7      joda 
    275   1.7      joda 	    for(p = SIMPLEQ_FIRST(&rom_image);
    276   1.7      joda 		p;
    277   1.7      joda 		p = SIMPLEQ_NEXT(p, next)) {
    278   1.7      joda 		if(p->rom_image == CARDBUS_CIS_ASI_ROM_IMAGE(cis_ptr)) {
    279   1.7      joda 		    bus_space_read_region_1(p->romt, p->romh,
    280   1.7      joda 					    CARDBUS_CIS_ADDR(cis_ptr),
    281   1.7      joda 					    tuples, 256);
    282   1.7      joda 		    found++;
    283   1.7      joda 		}
    284   1.7      joda 		break;
    285   1.7      joda 	    }
    286   1.7      joda 	    while((p = SIMPLEQ_FIRST(&rom_image)) != NULL) {
    287   1.7      joda 		SIMPLEQ_REMOVE_HEAD(&rom_image, p, next);
    288   1.7      joda 		free(p, M_DEVBUF);
    289   1.7      joda 	    }
    290   1.7      joda 	out:
    291   1.7      joda 	    exrom = cardbus_conf_read(cc, cf, tag, reg);
    292   1.7      joda 	    cardbus_conf_write(cc, cf, tag, reg, exrom & ~1);
    293   1.7      joda 	    splx(save);
    294   1.7      joda 	} else {
    295   1.7      joda 	    command = cardbus_conf_read(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG);
    296   1.7      joda 	    cardbus_conf_write(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG,
    297   1.7      joda 			       command | CARDBUS_COMMAND_MEM_ENABLE);
    298   1.7      joda 	    /* XXX byte order? */
    299   1.7      joda 	    bus_space_read_region_1(ca->ca_memt, bar_memh,
    300   1.7      joda 				    cis_ptr, tuples, 256);
    301   1.7      joda 	    found++;
    302   1.7      joda 	}
    303   1.7      joda 	command = cardbus_conf_read(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG);
    304   1.7      joda 	cardbus_conf_write(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG,
    305   1.7      joda 			   command & ~CARDBUS_COMMAND_MEM_ENABLE);
    306   1.7      joda 	cardbus_conf_write(cc, cf, tag, reg, 0);
    307   1.7      joda #if 0
    308   1.7      joda 	/* XXX unmap memory */
    309   1.7      joda 	(*ca->ca_ct->ct_cf->cardbus_space_free)(ca->ca_ct,
    310   1.7      joda 						ca->ca_ct->ct_sc->sc_rbus_memt,
    311   1.7      joda 						bar_memh, bar_size);
    312   1.7      joda #endif
    313   1.7      joda 	break;
    314   1.1      haya 
    315   1.7      joda #ifdef DIAGNOSTIC
    316   1.7      joda     default:
    317   1.8      joda 	panic("%s: bad CIS space (%d)", sc->sc_dev.dv_xname, cardbus_space);
    318   1.7      joda #endif
    319   1.7      joda     }
    320   1.7      joda     return !found;
    321   1.7      joda }
    322   1.1      haya 
    323  1.10      joda static void
    324  1.10      joda parse_tuple(u_int8_t *tuple, int len, void *data)
    325  1.10      joda {
    326  1.10      joda #ifdef CARDBUS_DEBUG
    327  1.10      joda     static const char __func__[] = "parse_tuple";
    328  1.10      joda #endif
    329  1.10      joda     struct cardbus_cis_info *cis = data;
    330  1.10      joda     int bar_index;
    331  1.10      joda     int i;
    332  1.10      joda     char *p;
    333  1.10      joda     switch(tuple[0]) {
    334  1.10      joda     case PCMCIA_CISTPL_MANFID:
    335  1.10      joda 	if(tuple[1] != 5) {
    336  1.10      joda 	    DPRINTF(("%s: wrong length manufacturer id (%d)\n",
    337  1.10      joda 		     __func__, tuple[1]));
    338  1.10      joda 	    break;
    339  1.10      joda 	}
    340  1.10      joda 	cis->manufacturer = tuple[2] | (tuple[3] << 8);
    341  1.10      joda 	cis->product = tuple[4] | (tuple[5] << 8);
    342  1.10      joda 	break;
    343  1.10      joda     case PCMCIA_CISTPL_VERS_1:
    344  1.10      joda 	memcpy(cis->cis1_info_buf, tuple + 2, tuple[1]);
    345  1.10      joda 	i = 0;
    346  1.10      joda 	p = cis->cis1_info_buf + 2;
    347  1.10      joda 	while(i < sizeof(cis->cis1_info) / sizeof(cis->cis1_info[0])) {
    348  1.10      joda 	    cis->cis1_info[i++] = p;
    349  1.10      joda 	    while(*p != '\0' && *p != '\xff')
    350  1.10      joda 		p++;
    351  1.10      joda 	    if(*p == '\xff')
    352  1.10      joda 		break;
    353  1.10      joda 	    p++;
    354  1.10      joda 	}
    355  1.10      joda 	break;
    356  1.10      joda     case PCMCIA_CISTPL_BAR:
    357  1.10      joda 	if(tuple[1] != 6) {
    358  1.10      joda 	    DPRINTF(("%s: BAR with short length (%d)\n", __func__, tuple[1]));
    359  1.10      joda 	    break;
    360  1.10      joda 	}
    361  1.10      joda 	bar_index = tuple[2] & 7;
    362  1.10      joda 	if(bar_index == 0) {
    363  1.10      joda 	    DPRINTF(("%s: invalid ASI in BAR tuple\n",
    364  1.10      joda 		     __func__, bar_index));
    365  1.10      joda 	    break;
    366  1.10      joda 	}
    367  1.10      joda 	bar_index--;
    368  1.10      joda 	cis->bar[bar_index].flags = tuple[2];
    369  1.10      joda 	cis->bar[bar_index].size = (tuple[4] << 0) |
    370  1.10      joda 				   (tuple[5] << 8) |
    371  1.10      joda 				   (tuple[6] << 16) |
    372  1.10      joda 				   (tuple[7] << 24);
    373  1.10      joda 	break;
    374  1.10      joda     case PCMCIA_CISTPL_FUNCID:
    375  1.10      joda 	cis->funcid = tuple[2];
    376  1.10      joda 	break;
    377  1.10      joda 
    378  1.10      joda     case PCMCIA_CISTPL_FUNCE:
    379  1.10      joda 	if(cis->funcid == PCMCIA_FUNCTION_NETWORK && tuple[1] >= 8) {
    380  1.10      joda 	    if(tuple[2] == PCMCIA_TPLFE_TYPE_LAN_NID) {
    381  1.10      joda 		if(tuple[3] > sizeof(cis->funce.network.netid)) {
    382  1.10      joda 		    DPRINTF(("%s: unknown network id type (len = %d)\n",
    383  1.10      joda 			     __func__, tuple[3]));
    384  1.10      joda 		} else {
    385  1.10      joda 		    memcpy(cis->funce.network.netid,
    386  1.10      joda 			   tuple + 4, tuple[3]);
    387  1.10      joda 		}
    388  1.10      joda 	    }
    389  1.10      joda 	}
    390  1.10      joda 	break;
    391  1.10      joda     }
    392  1.10      joda }
    393  1.10      joda 
    394   1.1      haya /*
    395   1.1      haya  * int cardbus_attach_card(struct cardbus_softc *sc)
    396   1.1      haya  *
    397   1.1      haya  *    This function attaches the card on the slot: turns on power,
    398   1.1      haya  *    reads and analyses tuple, sets consifuration index.
    399   1.1      haya  *
    400   1.1      haya  *    This function returns the number of recognised device functions.
    401   1.1      haya  *    If no functions are recognised, return 0.
    402   1.1      haya  */
    403   1.1      haya int
    404   1.1      haya cardbus_attach_card(sc)
    405   1.1      haya      struct cardbus_softc *sc;
    406   1.1      haya {
    407   1.1      haya   cardbus_chipset_tag_t cc;
    408   1.1      haya   cardbus_function_tag_t cf;
    409   1.1      haya   int cdstatus;
    410   1.1      haya   cardbustag_t tag;
    411   1.1      haya   cardbusreg_t id, class, cis_ptr;
    412   1.1      haya   cardbusreg_t bhlc;
    413   1.1      haya   u_int8_t tuple[2048];
    414   1.1      haya   int function, nfunction;
    415   1.1      haya   struct cardbus_devfunc **previous_next = &(sc->sc_funcs);
    416   1.1      haya   struct device *csc;
    417   1.1      haya   int no_work_funcs = 0;
    418   1.1      haya   cardbus_devfunc_t ct;
    419   1.1      haya 
    420   1.1      haya   cc = sc->sc_cc;
    421   1.1      haya   cf = sc->sc_cf;
    422   1.1      haya 
    423   1.1      haya   DPRINTF(("cardbus_attach_card: cb%d start\n", sc->sc_dev.dv_unit));
    424   1.1      haya 
    425   1.1      haya   /* inspect initial voltage */
    426   1.1      haya   if (0 == (cdstatus = (cf->cardbus_ctrl)(cc, CARDBUS_CD))) {
    427   1.1      haya     DPRINTF(("cardbusattach: no CardBus card on cb%d\n", sc->sc_dev.dv_unit));
    428   1.1      haya     return 0;
    429   1.1      haya   }
    430   1.1      haya 
    431   1.8      joda   enable_function(sc, cdstatus, 8); /* XXX use fake function 8 to
    432   1.8      joda 				       keep power on during whole
    433   1.8      joda 				       configuration */
    434   1.1      haya   function = 0;
    435   1.1      haya 
    436   1.1      haya   tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, function);
    437   1.1      haya 
    438   1.1      haya   /*
    439   1.1      haya    * Wait until power comes up.  Maxmum 500 ms.
    440   1.1      haya    */
    441   1.1      haya   {
    442   1.1      haya     int i;
    443   1.1      haya     for (i = 0; i < 5; ++i) {
    444   1.1      haya       id = cardbus_conf_read(cc, cf, tag, CARDBUS_ID_REG);
    445   1.1      haya       if (id != 0xffffffff && id != 0) {
    446   1.1      haya 	break;
    447   1.1      haya       }
    448   1.1      haya       delay(100*1000);		/* or tsleep */
    449   1.1      haya     }
    450   1.1      haya     if (i == 5) {
    451   1.1      haya       return 0;
    452   1.1      haya     }
    453   1.1      haya   }
    454   1.1      haya 
    455   1.1      haya   bhlc = cardbus_conf_read(cc, cf, tag, CARDBUS_BHLC_REG);
    456   1.1      haya   if (CARDBUS_LATTIMER(bhlc) < 0x10) {
    457   1.5      joda     bhlc &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
    458   1.1      haya     bhlc |= (0x10 << CARDBUS_LATTIMER_SHIFT);
    459   1.1      haya     cardbus_conf_write(cc, cf, tag, CARDBUS_BHLC_REG, bhlc);
    460   1.1      haya   }
    461   1.1      haya 
    462   1.1      haya   nfunction = CARDBUS_HDRTYPE_MULTIFN(bhlc) ? 8 : 1;
    463   1.1      haya 
    464   1.8      joda   for(function = 0; function < nfunction; function++) {
    465   1.8      joda       struct cardbus_attach_args ca;
    466   1.8      joda 
    467   1.8      joda       tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, function);
    468   1.8      joda 
    469   1.8      joda       id = cardbus_conf_read(cc, cf, tag, CARDBUS_ID_REG);
    470   1.8      joda       class = cardbus_conf_read(cc, cf, tag, CARDBUS_CLASS_REG);
    471   1.8      joda       cis_ptr = cardbus_conf_read(cc, cf, tag, CARDBUS_CIS_REG);
    472   1.8      joda 
    473   1.8      joda       /* Invalid vendor ID value? */
    474   1.8      joda       if (CARDBUS_VENDOR(id) == 0xffff)
    475   1.8      joda 	  continue;
    476   1.8      joda 
    477   1.8      joda       DPRINTF(("cardbus_attach_card: Vendor 0x%x, Product 0x%x, CIS 0x%x\n",
    478   1.8      joda 	       CARDBUS_VENDOR(id), CARDBUS_PRODUCT(id), cis_ptr));
    479   1.8      joda 
    480   1.8      joda       enable_function(sc, cdstatus, function);
    481   1.1      haya 
    482   1.8      joda       /* we need to allocate the ct here, since we might
    483   1.8      joda 	 need it when reading the CIS */
    484   1.8      joda       if (NULL == (ct = (cardbus_devfunc_t)malloc(sizeof(struct cardbus_devfunc),
    485   1.8      joda 						  M_DEVBUF, M_NOWAIT))) {
    486   1.8      joda 	  panic("no room for cardbus_tag");
    487   1.8      joda       }
    488   1.1      haya 
    489   1.8      joda       ct->ct_cc = sc->sc_cc;
    490   1.8      joda       ct->ct_cf = sc->sc_cf;
    491   1.8      joda       ct->ct_bus = sc->sc_bus;
    492   1.8      joda       ct->ct_dev = sc->sc_device;
    493   1.8      joda       ct->ct_func = function;
    494   1.8      joda       ct->ct_sc = sc;
    495   1.8      joda       ct->ct_next = NULL;
    496   1.8      joda       *previous_next = ct;
    497   1.8      joda 
    498   1.8      joda       ca.ca_unit = sc->sc_dev.dv_unit;
    499   1.8      joda       ca.ca_ct = ct;
    500   1.8      joda 
    501   1.8      joda       ca.ca_iot = sc->sc_iot;
    502   1.8      joda       ca.ca_memt = sc->sc_memt;
    503   1.8      joda       ca.ca_dmat = sc->sc_dmat;
    504   1.8      joda 
    505   1.8      joda       ca.ca_tag = tag;
    506   1.8      joda       ca.ca_device = sc->sc_device;
    507   1.8      joda       ca.ca_function = function;
    508   1.8      joda       ca.ca_id = id;
    509   1.8      joda       ca.ca_class = class;
    510   1.8      joda 
    511   1.8      joda       ca.ca_intrline = sc->sc_intrline;
    512   1.8      joda 
    513   1.8      joda       bzero(tuple, 2048);
    514   1.8      joda 
    515   1.8      joda       if(cardbus_read_tuples(&ca, cis_ptr, tuple, sizeof(tuple))) {
    516   1.8      joda 	  printf("cardbus_attach_card: failed to read CIS\n");
    517   1.8      joda 	  free(ct, M_DEVBUF);
    518   1.8      joda 	  disable_function(sc, function);
    519   1.8      joda 	  continue;
    520   1.8      joda       }
    521   1.7      joda 
    522  1.10      joda #ifdef CARDBUS_DEBUG
    523  1.10      joda       decode_tuples(tuple, 2048, print_tuple, NULL);
    524  1.10      joda #endif
    525  1.10      joda       decode_tuples(tuple, 2048, parse_tuple, &ca.ca_cis);
    526   1.7      joda 
    527   1.7      joda 
    528   1.8      joda       if (NULL == (csc = config_found_sm((void *)sc, &ca, cardbusprint, cardbussubmatch))) {
    529   1.8      joda 	  /* do not match */
    530   1.8      joda 	  disable_function(sc, function);
    531   1.8      joda 	  free(ct, M_DEVBUF);
    532   1.8      joda 	  *previous_next = NULL;
    533   1.8      joda       } else {
    534   1.8      joda 	  /* found */
    535   1.8      joda 	  previous_next = &(ct->ct_next);
    536   1.8      joda 	  ct->ct_device = csc;
    537   1.8      joda 	  ++no_work_funcs;
    538   1.8      joda       }
    539   1.1      haya   }
    540   1.8      joda   /* XXX power down pseudo function 8 (this will power down the card
    541   1.8      joda      if no functions were attached) */
    542   1.8      joda   disable_function(sc, 8);
    543   1.1      haya 
    544   1.8      joda   if(no_work_funcs == 0)
    545   1.8      joda       free(cc, M_DEVBUF);
    546   1.1      haya   return no_work_funcs;
    547   1.1      haya }
    548   1.1      haya 
    549   1.1      haya 
    550   1.1      haya static int
    551   1.1      haya #ifdef __BROKEN_INDIRECT_CONFIG
    552   1.1      haya cardbussubmatch(parent, match, aux)
    553   1.1      haya #else
    554   1.1      haya cardbussubmatch(parent, cf, aux)
    555   1.1      haya #endif
    556   1.1      haya      struct device *parent;
    557   1.1      haya #ifdef __BROKEN_INDIRECT_CONFIG
    558   1.1      haya      void *match;
    559   1.1      haya #else
    560   1.1      haya      struct cfdata *cf;
    561   1.1      haya #endif
    562   1.1      haya      void *aux;
    563   1.1      haya {
    564   1.1      haya #ifdef __BROKEN_INDIRECT_CONFIG
    565   1.1      haya   struct cfdata *cf = match;
    566   1.1      haya #endif
    567   1.1      haya   struct cardbus_attach_args *ca = aux;
    568   1.1      haya 
    569   1.1      haya   if (cf->cardbuscf_dev != CARDBUS_UNK_DEV &&
    570   1.1      haya       cf->cardbuscf_dev != ca->ca_unit) {
    571   1.1      haya     return 0;
    572   1.1      haya   }
    573   1.1      haya   if (cf->cardbuscf_function != CARDBUS_UNK_FUNCTION &&
    574   1.1      haya       cf->cardbuscf_function != ca->ca_function) {
    575   1.1      haya     return 0;
    576   1.1      haya   }
    577   1.1      haya 
    578   1.1      haya   return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    579   1.1      haya }
    580   1.1      haya 
    581   1.1      haya 
    582   1.1      haya 
    583   1.1      haya static int
    584   1.1      haya cardbusprint(aux, pnp)
    585   1.1      haya      void *aux;
    586   1.1      haya      const char *pnp;
    587   1.1      haya {
    588  1.10      joda     struct cardbus_attach_args *ca = aux;
    589  1.10      joda     char devinfo[256];
    590  1.10      joda     int i;
    591  1.10      joda     if (pnp) {
    592  1.10      joda 	pci_devinfo(ca->ca_id, ca->ca_class, 1, devinfo);
    593  1.10      joda 	for (i = 0; i < 4; i++) {
    594  1.10      joda 	    if (ca->ca_cis.cis1_info[i] == NULL)
    595  1.10      joda 		break;
    596  1.10      joda 	    if (i)
    597  1.10      joda 		printf(", ");
    598  1.10      joda 	    printf("%s", ca->ca_cis.cis1_info[i]);
    599  1.10      joda 	}
    600  1.10      joda 	if (i)
    601  1.10      joda 	    printf(" ");
    602  1.10      joda 	printf("(manufacturer 0x%x, product 0x%x)", ca->ca_cis.manufacturer,
    603  1.10      joda 	       ca->ca_cis.product);
    604  1.10      joda 	printf(" %s at %s", devinfo, pnp);
    605  1.10      joda     }
    606  1.10      joda     printf(" dev %d function %d", ca->ca_device, ca->ca_function);
    607   1.1      haya 
    608  1.10      joda     return UNCONF;
    609   1.1      haya }
    610   1.1      haya 
    611   1.1      haya 
    612   1.1      haya 
    613   1.1      haya 
    614   1.1      haya 
    615   1.1      haya 
    616   1.1      haya /*
    617   1.1      haya  * void *cardbus_intr_establish(cc, cf, irq, level, func, arg)
    618   1.1      haya  *   Interrupt handler of pccard.
    619   1.1      haya  *  args:
    620   1.1      haya  *   cardbus_chipset_tag_t *cc
    621   1.1      haya  *   int irq:
    622   1.1      haya  */
    623   1.1      haya void *
    624   1.1      haya cardbus_intr_establish(cc, cf, irq, level, func, arg)
    625   1.1      haya      cardbus_chipset_tag_t cc;
    626   1.1      haya      cardbus_function_tag_t cf;
    627   1.1      haya      cardbus_intr_handle_t irq;
    628   1.1      haya      int level;
    629   1.1      haya      int (*func) __P((void *));
    630   1.1      haya      void *arg;
    631   1.1      haya {
    632   1.1      haya   DPRINTF(("- cardbus_intr_establish: irq %d\n", irq));
    633   1.1      haya 
    634   1.1      haya   return (*cf->cardbus_intr_establish)(cc, irq, level, func, arg);
    635   1.1      haya }
    636   1.1      haya 
    637   1.1      haya 
    638   1.1      haya 
    639   1.1      haya /*
    640   1.1      haya  * void cardbus_intr_disestablish(cc, cf, handler)
    641   1.1      haya  *   Interrupt handler of pccard.
    642   1.1      haya  *  args:
    643   1.1      haya  *   cardbus_chipset_tag_t *cc
    644   1.1      haya  */
    645   1.1      haya void
    646   1.1      haya cardbus_intr_disestablish(cc, cf, handler)
    647   1.1      haya      cardbus_chipset_tag_t cc;
    648   1.1      haya      cardbus_function_tag_t cf;
    649   1.1      haya      void *handler;
    650   1.1      haya {
    651   1.1      haya   DPRINTF(("- pccard_intr_disestablish\n"));
    652   1.1      haya 
    653   1.1      haya  (*cf->cardbus_intr_disestablish)(cc, handler);
    654   1.1      haya   return;
    655   1.1      haya }
    656   1.1      haya 
    657   1.1      haya 
    658   1.1      haya 
    659   1.8      joda /* XXX this should be merged with cardbus_function_{enable,disable},
    660   1.8      joda    but we don't have a ct when these functions are called */
    661   1.8      joda 
    662   1.8      joda static void
    663   1.8      joda enable_function(sc, cdstatus, function)
    664   1.8      joda      struct cardbus_softc *sc;
    665   1.8      joda      int cdstatus;
    666   1.8      joda      int function;
    667   1.8      joda {
    668   1.8      joda     if(sc->sc_poweron_func == 0) {
    669   1.8      joda 	if (cdstatus & CARDBUS_3V_CARD) {
    670   1.8      joda 	    sc->sc_cf->cardbus_power(sc->sc_cc, CARDBUS_VCC_3V);
    671   1.8      joda 	}
    672   1.8      joda 	(sc->sc_cf->cardbus_ctrl)(sc->sc_cc, CARDBUS_RESET);
    673   1.8      joda     }
    674   1.8      joda     sc->sc_poweron_func |= (1 << function);
    675   1.8      joda }
    676   1.8      joda 
    677   1.8      joda static void
    678   1.8      joda disable_function(sc, function)
    679   1.8      joda      struct cardbus_softc *sc;
    680   1.8      joda      int function;
    681   1.8      joda {
    682   1.8      joda     sc->sc_poweron_func &= ~(1 << function);
    683   1.8      joda     if(sc->sc_poweron_func == 0) {
    684   1.8      joda 	/* power-off because no functions are enabled */
    685   1.8      joda 	sc->sc_cf->cardbus_power(sc->sc_cc, CARDBUS_VCC_0V);
    686   1.8      joda     }
    687   1.8      joda }
    688   1.8      joda 
    689   1.1      haya /*
    690   1.9      haya  * int cardbus_function_enable(struct cardbus_softc *sc, int func)
    691   1.1      haya  *
    692   1.1      haya  *   This function enables a function on a card.  When no power is
    693   1.1      haya  *  applied on the card, power will be applied on it.
    694   1.1      haya  */
    695   1.1      haya int
    696   1.9      haya cardbus_function_enable(sc, func)
    697   1.9      haya      struct cardbus_softc *sc;
    698   1.9      haya      int func;
    699   1.1      haya {
    700   1.1      haya   cardbus_chipset_tag_t cc = sc->sc_cc;
    701   1.1      haya   cardbus_function_tag_t cf = sc->sc_cf;
    702   1.1      haya   cardbusreg_t command;
    703   1.1      haya   cardbustag_t tag;
    704   1.1      haya 
    705   1.1      haya   DPRINTF(("entering cardbus_function_enable...  "));
    706   1.1      haya 
    707   1.1      haya   /* entering critical area */
    708   1.1      haya 
    709   1.8      joda   enable_function(sc, CARDBUS_3V_CARD, func); /* XXX: sc_vold should be used */
    710   1.1      haya 
    711   1.1      haya   /* exiting critical area */
    712   1.1      haya 
    713   1.9      haya   tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, func);
    714   1.9      haya 
    715   1.1      haya   command = cardbus_conf_read(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG);
    716   1.1      haya   command |= (CARDBUS_COMMAND_MEM_ENABLE | CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MASTER_ENABLE); /* XXX: good guess needed */
    717   1.9      haya 
    718   1.1      haya   cardbus_conf_write(cc, cf, tag, CARDBUS_COMMAND_STATUS_REG, command);
    719   1.1      haya 
    720   1.9      haya   cardbus_free_tag(cc, cf, tag);
    721   1.1      haya 
    722   1.1      haya   DPRINTF(("%x\n", sc->sc_poweron_func));
    723   1.1      haya 
    724   1.1      haya   return 0;
    725   1.1      haya }
    726   1.1      haya 
    727   1.1      haya 
    728   1.1      haya /*
    729   1.9      haya  * int cardbus_function_disable(struct cardbus_softc *, int func)
    730   1.1      haya  *
    731   1.1      haya  *   This function disable a function on a card.  When no functions are
    732   1.1      haya  *  enabled, it turns off the power.
    733   1.1      haya  */
    734   1.1      haya int
    735   1.9      haya cardbus_function_disable(sc, func)
    736   1.9      haya      struct cardbus_softc *sc;
    737   1.9      haya      int func;
    738   1.1      haya {
    739   1.1      haya 
    740   1.9      haya   DPRINTF(("entering cardbus_function_disable...  "));
    741   1.1      haya 
    742   1.8      joda   disable_function(sc, func);
    743   1.1      haya 
    744   1.1      haya   return 0;
    745   1.1      haya }
    746   1.1      haya 
    747   1.1      haya 
    748   1.1      haya 
    749   1.1      haya 
    750   1.1      haya 
    751   1.1      haya 
    752   1.1      haya 
    753   1.1      haya /*
    754   1.1      haya  * below this line, there are some functions for decoding tuples.
    755   1.1      haya  * They should go out from this file.
    756   1.1      haya  */
    757   1.1      haya 
    758  1.10      joda static u_int8_t *
    759  1.10      joda decode_tuple __P((u_int8_t *tuple, tuple_decode_func func, void *data));
    760   1.1      haya 
    761   1.1      haya static int
    762  1.10      joda decode_tuples(tuple, buflen, func, data)
    763   1.1      haya      u_int8_t *tuple;
    764   1.1      haya      int buflen;
    765  1.10      joda      tuple_decode_func func;
    766  1.10      joda      void *data;
    767   1.1      haya {
    768   1.1      haya   u_int8_t *tp = tuple;
    769   1.1      haya 
    770   1.1      haya   if (CISTPL_LINKTARGET != *tuple) {
    771   1.1      haya     DPRINTF(("WRONG TUPLE: 0x%x\n", *tuple));
    772   1.1      haya     return 0;
    773   1.1      haya   }
    774   1.1      haya 
    775  1.10      joda   while (NULL != (tp = decode_tuple(tp, func, data))) {
    776   1.1      haya     if (tuple + buflen < tp) {
    777   1.1      haya       break;
    778   1.1      haya     }
    779   1.1      haya   }
    780   1.1      haya 
    781   1.1      haya   return 1;
    782   1.1      haya }
    783   1.1      haya 
    784   1.1      haya 
    785   1.1      haya static u_int8_t *
    786  1.10      joda decode_tuple(tuple, func, data)
    787   1.1      haya      u_int8_t *tuple;
    788  1.10      joda      tuple_decode_func func;
    789  1.10      joda      void *data;
    790   1.1      haya {
    791  1.10      joda     u_int8_t type;
    792  1.10      joda     u_int8_t len;
    793   1.1      haya 
    794  1.10      joda     type = tuple[0];
    795  1.10      joda     len = tuple[1] + 2;
    796   1.1      haya 
    797  1.10      joda     (*func)(tuple, len, data);
    798   1.1      haya 
    799  1.10      joda     if (CISTPL_END == type) {
    800  1.10      joda 	return NULL;
    801   1.1      haya     }
    802   1.1      haya 
    803  1.10      joda     return tuple + len;
    804   1.1      haya }
    805   1.1      haya 
    806   1.1      haya 
    807   1.3  augustss #ifdef CARDBUS_DEBUG
    808  1.10      joda static char *tuple_name __P((int type));
    809  1.10      joda 
    810   1.1      haya static char *
    811   1.1      haya tuple_name(type)
    812   1.1      haya      int type;
    813   1.1      haya {
    814   1.1      haya   static char *tuple_name_s [] = {
    815   1.1      haya     "TPL_NULL", "TPL_DEVICE", "Reserved", "Reserved", /* 0-3 */
    816   1.1      haya     "CONFIG_CB", "CFTABLE_ENTRY_CB", "Reserved", "BAR", /* 4-7 */
    817   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 8-B */
    818   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* C-F */
    819   1.1      haya     "CHECKSUM", "LONGLINK_A", "LONGLINK_C", "LINKTARGET",	/* 10-13 */
    820   1.1      haya     "NO_LINK", "VERS_1", "ALTSTR", "DEVICE_A",
    821   1.1      haya     "JEDEC_C", "JEDEC_A", "CONFIG", "CFTABLE_ENTRY",
    822   1.1      haya     "DEVICE_OC", "DEVICE_OA", "DEVICE_GEO", "DEVICE_GEO_A",
    823   1.1      haya     "MANFID", "FUNCID", "FUNCE", "SWIL", /* 20-23 */
    824   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 24-27 */
    825   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 28-2B */
    826   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 2C-2F */
    827   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 30-33 */
    828   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 34-37 */
    829   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 38-3B */
    830   1.1      haya     "Reserved", "Reserved", "Reserved", "Reserved", /* 3C-3F */
    831   1.1      haya     "VERS_2", "FORMAT", "GEOMETRY", "BYTEORDER",
    832   1.1      haya     "DATE", "BATTERY", "ORG"
    833   1.1      haya   };
    834   1.1      haya #define NAME_LEN(x) (sizeof x / sizeof(x[0]))
    835   1.1      haya 
    836   1.1      haya   if (type > 0 && type < NAME_LEN(tuple_name_s)) {
    837   1.1      haya     return tuple_name_s[type];
    838   1.1      haya   } else if (0xff == type) {
    839   1.1      haya     return "END";
    840   1.1      haya   } else {
    841   1.1      haya     return "Reserved";
    842   1.1      haya   }
    843   1.1      haya }
    844  1.10      joda 
    845  1.10      joda static void
    846  1.10      joda print_tuple(tuple, len, data)
    847  1.10      joda      u_int8_t *tuple;
    848  1.10      joda      int len;
    849  1.10      joda      void *data;
    850  1.10      joda {
    851  1.10      joda     int i;
    852  1.10      joda 
    853  1.10      joda     printf("tuple: %s len %d\n", tuple_name(tuple[0]), len);
    854  1.10      joda 
    855  1.10      joda     for (i = 0; i < len; ++i) {
    856  1.10      joda 	if (i % 16 == 0) {
    857  1.10      joda 	    printf("  0x%2x:", i);
    858  1.10      joda 	}
    859  1.10      joda 	printf(" %x",tuple[i]);
    860  1.10      joda 	if (i % 16 == 15) {
    861  1.10      joda 	    printf("\n");
    862  1.10      joda 	}
    863  1.10      joda     }
    864  1.10      joda     if (i % 16 != 0) {
    865  1.10      joda 	printf("\n");
    866  1.10      joda     }
    867  1.10      joda }
    868  1.10      joda 
    869   1.3  augustss #endif
    870  1.10      joda 
    871