/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* PCI configuration space access routines
*/
#include <sys/bootconf.h>
#include <sys/pci_impl.h>
#include <sys/pci_cfgspace.h>
#include <sys/pci_cfgspace_impl.h>
#include <sys/pci_cfgacc.h>
#if defined(__xpv)
#include <sys/hypervisor.h>
#endif
#if defined(__xpv)
#endif
int pci_bios_maxbus;
int pci_bios_mech;
int pci_bios_vers;
/*
* These two variables can be used to force a configuration mechanism or
* to force which function is used to probe for the presence of the PCI bus.
*/
int PCI_CFG_TYPE = 0;
int PCI_PROBE_TYPE = 0;
/*
* No valid mcfg_mem_base by default, and accessing pci config space
* in mem-mapped way is disabled.
*/
/*
* Maximum offset in config space when not using MMIO
*/
/*
* These function pointers lead to the actual implementation routines
* for configuration space access. Normally they lead to either the
* pci_mech1_* or pci_mech2_* routines, but they can also lead to
* routines that work around chipset bugs.
* These functions are accessing pci config space via I/O way.
* Pci_cfgacc_get/put functions shoul be used as more common interfaces,
* which also provide accessing pci config space via mem-mapped way.
*/
/*
* Internal routines
*/
static int pci_check(void);
#if !defined(__xpv)
static int pci_check_bios(void);
static int pci_get_cfg_type(void);
#endif
/* for legacy io-based config space access */
/* for mmio-based config space access */
/* ..except Orion and Neptune, which have to have their own */
void
pci_cfgspace_init(void)
{
if (!pci_check()) {
}
}
/*
* type of configuration access method is used
*/
static int
pci_check(void)
{
/*
* Only do this once. NB: If this is not a PCI system, and we
* get called twice, we can't detect it and will probably die
* horribly when we try to ask the BIOS whether PCI is present.
* This code is safe *ONLY* during system startup when the
* BIOS is still available.
*/
return (TRUE);
#if defined(__xpv)
/*
* only support PCI config mechanism 1 in i86xpv. This should be fine
* since the other ones are workarounds for old broken H/W which won't
* be supported in i86xpv anyway.
*/
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
/*
* Since we can't get the BIOS info in i86xpv, we will do an
* exhaustive search of all PCI buses. We have to do this until
* we start using the PCI information in ACPI.
*/
}
#else /* !__xpv */
if (pci_bios_cfg_type == PCI_MECHANISM_NONE)
switch (pci_get_cfg_type()) {
case PCI_MECHANISM_1:
if (pci_is_broken_orion()) {
} else if (pci_check_amd_ioecs()) {
pci_iocfg_max_offset = 0xfff;
} else {
}
break;
case PCI_MECHANISM_2:
if (pci_check_neptune()) {
/*
* The BIOS for some systems with the Intel
* Neptune chipset seem to default to #2 even
* though the chipset can do #1. Override
* the BIOS so that MP systems will work
* correctly.
*/
} else {
}
break;
default:
return (FALSE);
}
#endif /* __xpv */
/*
* Try to get a valid mcfg_mem_base in early boot
* If failed, leave mem-mapped pci config space accessing disabled
* until pci boot code (pci_autoconfig) makes sure this is a PCIE
* platform.
*/
mcfg_mem_base = ecfginfo[0];
}
/* See pci_cfgacc.c */
return (TRUE);
}
#if !defined(__xpv)
static int
pci_check_bios(void)
{
/* the carry flag must not be set */
if (carryflag != 0)
return (PCI_MECHANISM_NONE);
return (PCI_MECHANISM_NONE);
/* ah (the high byte of ax) must be zero */
if ((ax & 0xff00) != 0)
return (PCI_MECHANISM_NONE);
switch (pci_bios_mech) {
default: /* ?!? */
case 0: /* supports neither? */
return (PCI_MECHANISM_NONE);
case 1:
case 3: /* supports both */
return (PCI_MECHANISM_1);
case 2:
return (PCI_MECHANISM_2);
}
}
static int
pci_get_cfg_type(void)
{
switch (PCI_CFG_TYPE) {
default:
case 0:
break;
case 1:
return (PCI_MECHANISM_1);
case 2:
return (PCI_MECHANISM_2);
case -1:
return (PCI_MECHANISM_NONE);
}
/* call one of the PCI detection algorithms */
switch (PCI_PROBE_TYPE) {
default:
case 0:
/* From pci_check() and pci_check_bios() */
return (pci_bios_cfg_type);
case -1:
return (PCI_MECHANISM_NONE);
}
}
#endif /* __xpv */