pci_impl.h revision bf8fc2340620695a402331e5da7c7db43264174d
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER START
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The contents of this file are subject to the terms of the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Common Development and Distribution License (the "License").
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You may not use this file except in compliance with the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * or http://www.opensolaris.org/os/licensing.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * See the License for the specific language governing permissions
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and limitations under the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When distributing Covered Code, include this CDDL HEADER in each
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If applicable, add the following below this CDDL HEADER, with the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * fields enclosed by brackets "[]" replaced with your own identifying
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * information: Portions Copyright [yyyy] [name of copyright owner]
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER END
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Use is subject to license terms.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#ifndef _SYS_PCI_IMPL_H
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define _SYS_PCI_IMPL_H
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#pragma ident "%Z%%M% %I% %E% SMI"
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#include <sys/dditypes.h>
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#include <sys/memlist.h>
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#ifdef __cplusplus
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kimextern "C" {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#endif
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#if defined(__i386) || defined(__amd64)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/*
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * There are two ways to access the PCI configuration space on X86
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Access method 2 is the older method
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Access method 1 is the newer method and is preferred because
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * of the problems in trying to lock the configuration space
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * for MP machines using method 2. See PCI Local BUS Specification
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Revision 2.0 section 3.6.4.1 for more details.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * In addition, on IBM Sandalfoot and a few related machines there's
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * still another mechanism. See PReP 1.1 section 6.1.7.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_MECHANISM_UNKNOWN -1
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_MECHANISM_NONE 0
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#if defined(__i386) || defined(__amd64)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_MECHANISM_1 1
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_MECHANISM_2 2
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#else
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#error "Unknown processor type"
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#endif
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#ifndef FALSE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define FALSE 0
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#endif
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#ifndef TRUE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define TRUE 1
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#endif
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_FUNC_MASK 0x07
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim/* these macros apply to Configuration Mechanism #1 */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_CONFADD 0xcf8
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_PMC 0xcfb
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_CONFDATA 0xcfc
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_CONE 0x80000000
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim#define PCI_CADDR1(bus, device, function, reg) \
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (PCI_CONE | (((bus) & 0xff) << 16) | (((device & 0x1f)) << 11) \
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim | (((function) & 0x7) << 8) | ((reg) & 0xfc))
/* these macros apply to Configuration Mechanism #2 */
#define PCI_CSE_PORT 0xcf8
#define PCI_FORW_PORT 0xcfa
#define PCI_CADDR2(device, indx) \
(0xc000 | (((device) & 0xf) << 8) | (indx))
typedef struct pci_acc_cfblk {
uchar_t c_busnum; /* bus number */
uchar_t c_devnum; /* device number */
uchar_t c_funcnum; /* function number */
uchar_t c_fill; /* reserve field */
} pci_acc_cfblk_t;
struct pci_bus_resource {
struct memlist *io_ports;
struct memlist *mem_space;
struct memlist *pmem_space;
dev_info_t *dip; /* devinfo node */
void *privdata; /* private data for configuration */
uchar_t par_bus; /* parent bus number */
uchar_t sub_bus; /* highest bus number beyond this bridge */
uchar_t root_addr; /* legacy peer bus address assignment */
uchar_t padding1;
#ifdef _LP64
uint32_t padding2;
#endif
};
extern struct pci_bus_resource *pci_bus_res;
/*
* For now, x86-only to avoid conflicts with <sys/memlist_impl.h>
*/
extern struct memlist *memlist_alloc(void);
extern void memlist_free(struct memlist *);
extern void memlist_insert(struct memlist **, uint64_t, uint64_t);
extern int memlist_remove(struct memlist **, uint64_t, uint64_t);
extern uint64_t memlist_find(struct memlist **, uint64_t, int);
extern void memlist_dump(struct memlist *);
extern struct memlist *memlist_dup(struct memlist *);
extern int memlist_count(struct memlist *);
#endif /* __i386 || __amd64 */
/*
* PCI capability related definitions.
*/
/*
* Minimum number of dwords to be saved.
*/
#define PCI_MSI_MIN_WORDS 3
#define PCI_PCIX_MIN_WORDS 2
#define PCI_PCIE_MIN_WORDS 5
/*
* Total number of dwords to be saved.
*/
#define PCI_PMCAP_NDWORDS 2
#define PCI_AGP_NDWORDS 3
#define PCI_SLOTID_NDWORDS 1
#define PCI_MSIX_NDWORDS 3
#define PCI_CAP_SZUNKNOWN 0
#define CAP_ID(confhdl, cap_ptr, xspace) \
((xspace) ? 0 : pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_ID))
#define NEXT_CAP(confhdl, cap_ptr, xspace) \
((xspace) ? 0 : \
pci_config_get8((confhdl), (cap_ptr) + PCI_CAP_NEXT_PTR))
extern int pci_resource_setup(dev_info_t *);
extern void pci_resource_destroy(dev_info_t *);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_PCI_IMPL_H */