pci_machdep.c revision 1.3
11.3Skiyohara/*	$NetBSD: pci_machdep.c,v 1.3 2013/01/12 08:40:51 kiyohara Exp $	*/
21.1Skiyohara/*
31.2Skiyohara * Copyright (c) 2009, 2010 KIYOHARA Takashi
41.1Skiyohara * All rights reserved.
51.1Skiyohara *
61.1Skiyohara * Redistribution and use in source and binary forms, with or without
71.1Skiyohara * modification, are permitted provided that the following conditions
81.1Skiyohara * are met:
91.1Skiyohara * 1. Redistributions of source code must retain the above copyright
101.1Skiyohara *    notice, this list of conditions and the following disclaimer.
111.1Skiyohara * 2. Redistributions in binary form must reproduce the above copyright
121.1Skiyohara *    notice, this list of conditions and the following disclaimer in the
131.1Skiyohara *    documentation and/or other materials provided with the distribution.
141.1Skiyohara *
151.1Skiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.1Skiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
171.1Skiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
181.1Skiyohara * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
191.1Skiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
201.1Skiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
211.1Skiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Skiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
231.1Skiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
241.1Skiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Skiyohara * POSSIBILITY OF SUCH DAMAGE.
261.1Skiyohara */
271.1Skiyohara#include <sys/cdefs.h>
281.3Skiyohara__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.3 2013/01/12 08:40:51 kiyohara Exp $");
291.1Skiyohara
301.1Skiyohara#include <machine/bus.h>
311.2Skiyohara#include <machine/sal.h>
321.2Skiyohara
331.1Skiyohara#include <dev/pci/pcivar.h>
341.1Skiyohara#include <dev/pci/pcireg.h>
351.1Skiyohara#include <dev/pci/pcidevs.h>
361.1Skiyohara
371.1Skiyohara
381.2Skiyoharavoid
391.2Skiyoharapci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
401.2Skiyohara{
411.2Skiyohara
421.2Skiyohara	/* Nothing */
431.2Skiyohara}
441.2Skiyohara
451.2Skiyoharaint
461.2Skiyoharapci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
471.2Skiyohara{
481.2Skiyohara
491.2Skiyohara	 return 32;	/* 32 device/bus */
501.2Skiyohara}
511.2Skiyohara
521.1Skiyoharapcitag_t
531.1Skiyoharapci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
541.1Skiyohara{
551.2Skiyohara
561.2Skiyohara#if DIAGNOSTIC
571.2Skiyohara	if (bus >= 256 || device >= 32 || function >= 8)
581.2Skiyohara		panic("%s: bad request", __func__);
591.2Skiyohara#endif
601.2Skiyohara
611.2Skiyohara	return (bus << 16) | (device << 11) | (function << 8);
621.2Skiyohara}
631.2Skiyohara
641.2Skiyoharavoid
651.2Skiyoharapci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
661.2Skiyohara{
671.2Skiyohara
681.2Skiyohara	if (bp != NULL)
691.2Skiyohara		*bp = (tag >> 16) & 0xff;
701.2Skiyohara	if (dp != NULL)
711.2Skiyohara		*dp = (tag >> 11) & 0x1f;
721.2Skiyohara	if (fp != NULL)
731.2Skiyohara		*fp = (tag >> 8) & 0x07;
741.1Skiyohara}
751.1Skiyohara
761.1Skiyoharapcireg_t
771.1Skiyoharapci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
781.1Skiyohara{
791.2Skiyohara	struct ia64_sal_result res;
801.2Skiyohara
811.2Skiyohara	res = ia64_sal_entry(SAL_PCI_CONFIG_READ,
821.2Skiyohara	    tag | reg, sizeof(pcireg_t), 0, 0, 0, 0, 0);
831.2Skiyohara	if (res.sal_status < 0)
841.2Skiyohara		return -1;
851.2Skiyohara	else
861.2Skiyohara		return res.sal_result[0];
871.1Skiyohara}
881.1Skiyohara
891.1Skiyoharavoid
901.1Skiyoharapci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
911.1Skiyohara{
921.3Skiyohara	struct ia64_sal_result res;
931.2Skiyohara
941.3Skiyohara	res = ia64_sal_entry(SAL_PCI_CONFIG_WRITE,
951.2Skiyohara	    tag | reg, sizeof(pcireg_t), val, 0, 0, 0, 0);
961.3Skiyohara	if (res.sal_status < 0)
971.3Skiyohara		printf("pci configuration write failed\n");
981.1Skiyohara}
99