1*e552812aSscole /* $NetBSD: pci_machdep.c,v 1.6 2018/03/01 23:01:19 scole Exp $ */
2833b1484Skiyohara /*
30fe98814Skiyohara * Copyright (c) 2009, 2010 KIYOHARA Takashi
4833b1484Skiyohara * All rights reserved.
5833b1484Skiyohara *
6833b1484Skiyohara * Redistribution and use in source and binary forms, with or without
7833b1484Skiyohara * modification, are permitted provided that the following conditions
8833b1484Skiyohara * are met:
9833b1484Skiyohara * 1. Redistributions of source code must retain the above copyright
10833b1484Skiyohara * notice, this list of conditions and the following disclaimer.
11833b1484Skiyohara * 2. Redistributions in binary form must reproduce the above copyright
12833b1484Skiyohara * notice, this list of conditions and the following disclaimer in the
13833b1484Skiyohara * documentation and/or other materials provided with the distribution.
14833b1484Skiyohara *
15833b1484Skiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16833b1484Skiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17833b1484Skiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18833b1484Skiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19833b1484Skiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20833b1484Skiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21833b1484Skiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22833b1484Skiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23833b1484Skiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24833b1484Skiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25833b1484Skiyohara * POSSIBILITY OF SUCH DAMAGE.
26833b1484Skiyohara */
27833b1484Skiyohara #include <sys/cdefs.h>
28*e552812aSscole __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.6 2018/03/01 23:01:19 scole Exp $");
29833b1484Skiyohara
30833b1484Skiyohara #include <machine/bus.h>
310fe98814Skiyohara #include <machine/sal.h>
320fe98814Skiyohara
33833b1484Skiyohara #include <dev/pci/pcivar.h>
34833b1484Skiyohara #include <dev/pci/pcireg.h>
35833b1484Skiyohara #include <dev/pci/pcidevs.h>
36833b1484Skiyohara
37833b1484Skiyohara
380fe98814Skiyohara void
pci_attach_hook(device_t parent,device_t self,struct pcibus_attach_args * pba)390fe98814Skiyohara pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
400fe98814Skiyohara {
410fe98814Skiyohara
420fe98814Skiyohara /* Nothing */
430fe98814Skiyohara }
440fe98814Skiyohara
450fe98814Skiyohara int
pci_bus_maxdevs(pci_chipset_tag_t pc,int busno)460fe98814Skiyohara pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
470fe98814Skiyohara {
480fe98814Skiyohara
490fe98814Skiyohara return 32; /* 32 device/bus */
500fe98814Skiyohara }
510fe98814Skiyohara
52833b1484Skiyohara pcitag_t
pci_make_tag(pci_chipset_tag_t pc,int bus,int device,int function)53833b1484Skiyohara pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
54833b1484Skiyohara {
550fe98814Skiyohara
560fe98814Skiyohara #if DIAGNOSTIC
570fe98814Skiyohara if (bus >= 256 || device >= 32 || function >= 8)
580fe98814Skiyohara panic("%s: bad request", __func__);
590fe98814Skiyohara #endif
600fe98814Skiyohara
610fe98814Skiyohara return (bus << 16) | (device << 11) | (function << 8);
620fe98814Skiyohara }
630fe98814Skiyohara
640fe98814Skiyohara void
pci_decompose_tag(pci_chipset_tag_t pc,pcitag_t tag,int * bp,int * dp,int * fp)650fe98814Skiyohara pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
660fe98814Skiyohara {
670fe98814Skiyohara
680fe98814Skiyohara if (bp != NULL)
690fe98814Skiyohara *bp = (tag >> 16) & 0xff;
700fe98814Skiyohara if (dp != NULL)
710fe98814Skiyohara *dp = (tag >> 11) & 0x1f;
720fe98814Skiyohara if (fp != NULL)
730fe98814Skiyohara *fp = (tag >> 8) & 0x07;
74833b1484Skiyohara }
75833b1484Skiyohara
76833b1484Skiyohara pcireg_t
pci_conf_read(pci_chipset_tag_t pc,pcitag_t tag,int reg)77833b1484Skiyohara pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
78833b1484Skiyohara {
790fe98814Skiyohara struct ia64_sal_result res;
800fe98814Skiyohara
81605f564fSmsaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
82605f564fSmsaitoh return -1;
83605f564fSmsaitoh
840fe98814Skiyohara res = ia64_sal_entry(SAL_PCI_CONFIG_READ,
850fe98814Skiyohara tag | reg, sizeof(pcireg_t), 0, 0, 0, 0, 0);
860fe98814Skiyohara if (res.sal_status < 0)
870fe98814Skiyohara return -1;
880fe98814Skiyohara else
890fe98814Skiyohara return res.sal_result[0];
90833b1484Skiyohara }
91833b1484Skiyohara
92833b1484Skiyohara void
pci_conf_write(pci_chipset_tag_t pc,pcitag_t tag,int reg,pcireg_t val)93833b1484Skiyohara pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
94833b1484Skiyohara {
95988c5688Skiyohara struct ia64_sal_result res;
960fe98814Skiyohara
97605f564fSmsaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
98605f564fSmsaitoh return;
99605f564fSmsaitoh
100988c5688Skiyohara res = ia64_sal_entry(SAL_PCI_CONFIG_WRITE,
1010fe98814Skiyohara tag | reg, sizeof(pcireg_t), val, 0, 0, 0, 0);
102988c5688Skiyohara if (res.sal_status < 0)
103988c5688Skiyohara printf("pci configuration write failed\n");
104833b1484Skiyohara }
105