Home | History | Annotate | Line # | Download | only in pci
      1  1.28   thorpej /* $NetBSD: apecs_pci.c,v 1.28 2021/06/25 03:45:59 thorpej Exp $ */
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.6       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5   1.1       cgd  * All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Author: Chris G. Demetriou
      8  1.25      matt  *
      9   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     10   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     11   1.1       cgd  * notice and this permission notice appear in all copies of the
     12   1.1       cgd  * software, derivative works or modified versions, and any portions
     13   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.25      matt  *
     15  1.25      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.25      matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.25      matt  *
     19   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     20   1.1       cgd  *
     21   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.1       cgd  *  School of Computer Science
     23   1.1       cgd  *  Carnegie Mellon University
     24   1.1       cgd  *  Pittsburgh PA 15213-3890
     25   1.1       cgd  *
     26   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     27   1.1       cgd  * rights to redistribute these changes.
     28   1.1       cgd  */
     29  1.12       cgd 
     30  1.13       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31  1.13       cgd 
     32  1.28   thorpej __KERNEL_RCSID(0, "$NetBSD: apecs_pci.c,v 1.28 2021/06/25 03:45:59 thorpej Exp $");
     33   1.1       cgd 
     34   1.1       cgd #include <sys/param.h>
     35   1.1       cgd #include <sys/systm.h>
     36   1.1       cgd #include <sys/kernel.h>
     37   1.1       cgd #include <sys/device.h>
     38  1.18       mrg 
     39   1.1       cgd #include <dev/pci/pcireg.h>
     40   1.1       cgd #include <dev/pci/pcivar.h>
     41   1.1       cgd #include <alpha/pci/apecsreg.h>
     42   1.4       cgd #include <alpha/pci/apecsvar.h>
     43   1.1       cgd 
     44  1.27   thorpej static pcireg_t	apecs_conf_read(void *, pcitag_t, int);
     45  1.27   thorpej static void	apecs_conf_write(void *, pcitag_t, int, pcireg_t);
     46   1.1       cgd 
     47   1.5       cgd void
     48  1.21       dsl apecs_pci_init(pci_chipset_tag_t pc, void *v)
     49   1.5       cgd {
     50   1.5       cgd 
     51   1.5       cgd 	pc->pc_conf_v = v;
     52   1.5       cgd 	pc->pc_conf_read = apecs_conf_read;
     53   1.5       cgd 	pc->pc_conf_write = apecs_conf_write;
     54   1.5       cgd }
     55   1.5       cgd 
     56  1.27   thorpej static pcireg_t
     57  1.21       dsl apecs_conf_read(void *cpv, pcitag_t tag, int offset)
     58   1.4       cgd {
     59   1.4       cgd 	struct apecs_config *acp = cpv;
     60   1.5       cgd 	pcireg_t *datap, data;
     61   1.4       cgd 	int s, secondary, ba;
     62   1.4       cgd 	int32_t old_haxr2;					/* XXX */
     63   1.4       cgd 
     64  1.26   msaitoh 	if ((unsigned int)offset >= PCI_CONF_SIZE)
     65  1.26   msaitoh 		return (pcireg_t) -1;
     66  1.26   msaitoh 
     67  1.10       cgd 	s = 0;					/* XXX gcc -Wuninitialized */
     68  1.10       cgd 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
     69  1.10       cgd 
     70   1.5       cgd 	/* secondary if bus # != 0 */
     71  1.19   thorpej 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
     72   1.4       cgd 	if (secondary) {
     73   1.4       cgd 		s = splhigh();
     74   1.4       cgd 		old_haxr2 = REGVAL(EPIC_HAXR2);
     75   1.7       cgd 		alpha_mb();
     76   1.4       cgd 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
     77   1.7       cgd 		alpha_mb();
     78   1.4       cgd 	}
     79   1.1       cgd 
     80   1.7       cgd 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
     81   1.4       cgd 	    tag << 5UL |					/* XXX */
     82   1.4       cgd 	    (offset & ~0x03) << 5 |				/* XXX */
     83   1.4       cgd 	    0 << 5 |						/* XXX */
     84   1.4       cgd 	    0x3 << 3);						/* XXX */
     85   1.5       cgd 	data = (pcireg_t)-1;
     86   1.4       cgd 	if (!(ba = badaddr(datap, sizeof *datap)))
     87   1.4       cgd 		data = *datap;
     88   1.4       cgd 
     89   1.4       cgd 	if (secondary) {
     90   1.7       cgd 		alpha_mb();
     91   1.4       cgd 		REGVAL(EPIC_HAXR2) = old_haxr2;
     92   1.7       cgd 		alpha_mb();
     93   1.4       cgd 		splx(s);
     94   1.4       cgd 	}
     95   1.1       cgd 
     96   1.1       cgd #if 0
     97   1.9  christos 	printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
     98   1.4       cgd 	    data, datap, ba ? " (badaddr)" : "");
     99   1.1       cgd #endif
    100   1.1       cgd 
    101   1.4       cgd 	return data;
    102   1.1       cgd }
    103   1.1       cgd 
    104  1.27   thorpej static void
    105  1.21       dsl apecs_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
    106   1.4       cgd {
    107   1.4       cgd 	struct apecs_config *acp = cpv;
    108   1.5       cgd 	pcireg_t *datap;
    109   1.4       cgd 	int s, secondary;
    110   1.4       cgd 	int32_t old_haxr2;					/* XXX */
    111  1.10       cgd 
    112  1.26   msaitoh 	if ((unsigned int)offset >= PCI_CONF_SIZE)
    113  1.26   msaitoh 		return;
    114  1.26   msaitoh 
    115  1.10       cgd 	s = 0;					/* XXX gcc -Wuninitialized */
    116  1.10       cgd 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    117   1.4       cgd 
    118   1.5       cgd 	/* secondary if bus # != 0 */
    119  1.19   thorpej 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
    120   1.4       cgd 	if (secondary) {
    121   1.4       cgd 		s = splhigh();
    122   1.4       cgd 		old_haxr2 = REGVAL(EPIC_HAXR2);
    123   1.7       cgd 		alpha_mb();
    124   1.4       cgd 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
    125   1.7       cgd 		alpha_mb();
    126   1.1       cgd 	}
    127   1.1       cgd 
    128   1.7       cgd 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
    129   1.4       cgd 	    tag << 5UL |					/* XXX */
    130   1.4       cgd 	    (offset & ~0x03) << 5 |				/* XXX */
    131   1.4       cgd 	    0 << 5 |						/* XXX */
    132   1.4       cgd 	    0x3 << 3);						/* XXX */
    133  1.17      ross 
    134  1.17      ross 	alpha_mb();
    135   1.4       cgd 	*datap = data;
    136  1.17      ross 	alpha_mb();
    137  1.17      ross 	alpha_mb();
    138   1.1       cgd 
    139   1.4       cgd 	if (secondary) {
    140   1.7       cgd 		alpha_mb();
    141   1.4       cgd 		REGVAL(EPIC_HAXR2) = old_haxr2;
    142   1.7       cgd 		alpha_mb();
    143   1.4       cgd 		splx(s);
    144   1.1       cgd 	}
    145   1.1       cgd 
    146   1.1       cgd #if 0
    147   1.9  christos 	printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
    148   1.1       cgd 	    reg, data, datap);
    149   1.1       cgd #endif
    150   1.1       cgd }
    151