1 1.13 thorpej /* $NetBSD: irongate_pci.c,v 1.13 2024/04/03 04:30:30 thorpej Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /*- 4 1.1 thorpej * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 1.1 thorpej * All rights reserved. 6 1.1 thorpej * 7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.1 thorpej * by Jason R. Thorpe. 9 1.1 thorpej * 10 1.1 thorpej * Redistribution and use in source and binary forms, with or without 11 1.1 thorpej * modification, are permitted provided that the following conditions 12 1.1 thorpej * are met: 13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright 14 1.1 thorpej * notice, this list of conditions and the following disclaimer. 15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the 17 1.1 thorpej * documentation and/or other materials provided with the distribution. 18 1.1 thorpej * 19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 thorpej */ 31 1.1 thorpej 32 1.1 thorpej /* 33 1.1 thorpej * PCI Configuration Space support for the AMD 751 (``Irongate'') core logic 34 1.1 thorpej * chipset. 35 1.1 thorpej */ 36 1.1 thorpej 37 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 38 1.1 thorpej 39 1.13 thorpej __KERNEL_RCSID(0, "$NetBSD: irongate_pci.c,v 1.13 2024/04/03 04:30:30 thorpej Exp $"); 40 1.1 thorpej 41 1.1 thorpej #include <sys/param.h> 42 1.1 thorpej #include <sys/systm.h> 43 1.1 thorpej #include <sys/kernel.h> 44 1.1 thorpej #include <sys/device.h> 45 1.2 mrg 46 1.1 thorpej #include <dev/pci/pcireg.h> 47 1.1 thorpej #include <dev/pci/pcivar.h> 48 1.1 thorpej #include <alpha/pci/irongatereg.h> 49 1.1 thorpej #include <alpha/pci/irongatevar.h> 50 1.1 thorpej 51 1.11 thorpej static pcireg_t irongate_conf_read(void *, pcitag_t, int); 52 1.11 thorpej static void irongate_conf_write(void *, pcitag_t, int, pcireg_t); 53 1.1 thorpej 54 1.1 thorpej /* AMD 751 systems are always single-processor, so this is easy. */ 55 1.1 thorpej #define PCI_CONF_LOCK(s) (s) = splhigh() 56 1.1 thorpej #define PCI_CONF_UNLOCK(s) splx((s)) 57 1.1 thorpej 58 1.1 thorpej #define PCI_CONF_ADDR (IRONGATE_IO_BASE|IRONGATE_CONFADDR) 59 1.1 thorpej #define PCI_CONF_DATA (IRONGATE_IO_BASE|IRONGATE_CONFDATA) 60 1.1 thorpej 61 1.9 matt #define REGVAL(r) (*(volatile uint32_t *)ALPHA_PHYS_TO_K0SEG(r)) 62 1.1 thorpej 63 1.1 thorpej void 64 1.1 thorpej irongate_pci_init(pci_chipset_tag_t pc, void *v) 65 1.1 thorpej { 66 1.1 thorpej 67 1.1 thorpej pc->pc_conf_v = v; 68 1.1 thorpej pc->pc_conf_read = irongate_conf_read; 69 1.1 thorpej pc->pc_conf_write = irongate_conf_write; 70 1.1 thorpej } 71 1.1 thorpej 72 1.11 thorpej static pcireg_t 73 1.1 thorpej irongate_conf_read(void *ipv, pcitag_t tag, int offset) 74 1.1 thorpej { 75 1.12 thorpej int b, d; 76 1.1 thorpej 77 1.10 msaitoh if ((unsigned int)offset >= PCI_CONF_SIZE) 78 1.10 msaitoh return (pcireg_t) -1; 79 1.10 msaitoh 80 1.12 thorpej struct irongate_config * const icp = ipv; 81 1.12 thorpej 82 1.1 thorpej /* 83 1.1 thorpej * The AMD 751 appears in PCI configuration space, but 84 1.1 thorpej * that is ... counter-intuitive to the way we normally 85 1.1 thorpej * attach PCI-Host bridges on the Alpha. So, filter out 86 1.1 thorpej * the AMD 751 device here. We provide a private entry 87 1.1 thorpej * point for getting at it from machdep code. 88 1.1 thorpej */ 89 1.12 thorpej pci_decompose_tag(&icp->ic_pc, tag, &b, &d, NULL); 90 1.12 thorpej if (b == 0 && d == IRONGATE_PCIHOST_DEV && offset == PCI_ID_REG) 91 1.1 thorpej return ((pcireg_t) -1); 92 1.1 thorpej 93 1.1 thorpej return (irongate_conf_read0(ipv, tag, offset)); 94 1.1 thorpej } 95 1.1 thorpej 96 1.1 thorpej pcireg_t 97 1.1 thorpej irongate_conf_read0(void *ipv, pcitag_t tag, int offset) 98 1.1 thorpej { 99 1.1 thorpej pcireg_t data; 100 1.1 thorpej int s; 101 1.1 thorpej 102 1.10 msaitoh if ((unsigned int)offset >= PCI_CONF_SIZE) 103 1.10 msaitoh return (pcireg_t) -1; 104 1.10 msaitoh 105 1.1 thorpej PCI_CONF_LOCK(s); 106 1.1 thorpej REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff)); 107 1.1 thorpej alpha_mb(); 108 1.1 thorpej data = REGVAL(PCI_CONF_DATA); 109 1.13 thorpej alpha_mb(); 110 1.1 thorpej REGVAL(PCI_CONF_ADDR) = 0; 111 1.1 thorpej alpha_mb(); 112 1.1 thorpej PCI_CONF_UNLOCK(s); 113 1.1 thorpej 114 1.1 thorpej return (data); 115 1.1 thorpej } 116 1.1 thorpej 117 1.11 thorpej static void 118 1.1 thorpej irongate_conf_write(void *ipv, pcitag_t tag, int offset, pcireg_t data) 119 1.1 thorpej { 120 1.1 thorpej int s; 121 1.1 thorpej 122 1.10 msaitoh if ((unsigned int)offset >= PCI_CONF_SIZE) 123 1.10 msaitoh return; 124 1.10 msaitoh 125 1.1 thorpej PCI_CONF_LOCK(s); 126 1.1 thorpej REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff)); 127 1.1 thorpej alpha_mb(); 128 1.1 thorpej REGVAL(PCI_CONF_DATA) = data; 129 1.1 thorpej alpha_mb(); 130 1.1 thorpej REGVAL(PCI_CONF_ADDR) = 0; 131 1.1 thorpej alpha_mb(); 132 1.1 thorpej PCI_CONF_UNLOCK(s); 133 1.1 thorpej } 134