1/* $NetBSD: pci_machdep.c,v 1.6 2018/03/01 23:01:19 scole Exp $ */ 2/* 3 * Copyright (c) 2009, 2010 KIYOHARA Takashi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27#include <sys/cdefs.h> 28__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.6 2018/03/01 23:01:19 scole Exp $"); 29 30#include <machine/bus.h> 31#include <machine/sal.h> 32 33#include <dev/pci/pcivar.h> 34#include <dev/pci/pcireg.h> 35#include <dev/pci/pcidevs.h> 36 37 38void 39pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba) 40{ 41 42 /* Nothing */ 43} 44 45int 46pci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 47{ 48 49 return 32; /* 32 device/bus */ 50} 51 52pcitag_t 53pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function) 54{ 55 56#if DIAGNOSTIC 57 if (bus >= 256 || device >= 32 || function >= 8) 58 panic("%s: bad request", __func__); 59#endif 60 61 return (bus << 16) | (device << 11) | (function << 8); 62} 63 64void 65pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp) 66{ 67 68 if (bp != NULL) 69 *bp = (tag >> 16) & 0xff; 70 if (dp != NULL) 71 *dp = (tag >> 11) & 0x1f; 72 if (fp != NULL) 73 *fp = (tag >> 8) & 0x07; 74} 75 76pcireg_t 77pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) 78{ 79 struct ia64_sal_result res; 80 81 if ((unsigned int)reg >= PCI_CONF_SIZE) 82 return -1; 83 84 res = ia64_sal_entry(SAL_PCI_CONFIG_READ, 85 tag | reg, sizeof(pcireg_t), 0, 0, 0, 0, 0); 86 if (res.sal_status < 0) 87 return -1; 88 else 89 return res.sal_result[0]; 90} 91 92void 93pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val) 94{ 95 struct ia64_sal_result res; 96 97 if ((unsigned int)reg >= PCI_CONF_SIZE) 98 return; 99 100 res = ia64_sal_entry(SAL_PCI_CONFIG_WRITE, 101 tag | reg, sizeof(pcireg_t), val, 0, 0, 0, 0); 102 if (res.sal_status < 0) 103 printf("pci configuration write failed\n"); 104} 105