14f5e7dd7Smrg/*
24f5e7dd7Smrg * (C) Copyright IBM Corporation 2006
3e432255dSmrg * Copyright 2009 Red Hat, Inc.
44f5e7dd7Smrg * All Rights Reserved.
54f5e7dd7Smrg *
64f5e7dd7Smrg * Permission is hereby granted, free of charge, to any person obtaining a
74f5e7dd7Smrg * copy of this software and associated documentation files (the "Software"),
84f5e7dd7Smrg * to deal in the Software without restriction, including without limitation
94f5e7dd7Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
104f5e7dd7Smrg * license, and/or sell copies of the Software, and to permit persons to whom
114f5e7dd7Smrg * the Software is furnished to do so, subject to the following conditions:
124f5e7dd7Smrg *
134f5e7dd7Smrg * The above copyright notice and this permission notice (including the next
144f5e7dd7Smrg * paragraph) shall be included in all copies or substantial portions of the
154f5e7dd7Smrg * Software.
164f5e7dd7Smrg *
174f5e7dd7Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184f5e7dd7Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194f5e7dd7Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
204f5e7dd7Smrg * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
214f5e7dd7Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
224f5e7dd7Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
234f5e7dd7Smrg * DEALINGS IN THE SOFTWARE.
244f5e7dd7Smrg */
2549f872b5Smrg/*
2649f872b5Smrg * Copyright (c) 2007 Paulo R. Zanoni, Tiago Vignatti
2749f872b5Smrg *
2849f872b5Smrg * Permission is hereby granted, free of charge, to any person
2949f872b5Smrg * obtaining a copy of this software and associated documentation
3049f872b5Smrg * files (the "Software"), to deal in the Software without
3149f872b5Smrg * restriction, including without limitation the rights to use,
3249f872b5Smrg * copy, modify, merge, publish, distribute, sublicense, and/or sell
3349f872b5Smrg * copies of the Software, and to permit persons to whom the
3449f872b5Smrg * Software is furnished to do so, subject to the following
3549f872b5Smrg * conditions:
3649f872b5Smrg *
3749f872b5Smrg * The above copyright notice and this permission notice shall be
3849f872b5Smrg * included in all copies or substantial portions of the Software.
3949f872b5Smrg *
4049f872b5Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4149f872b5Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
4249f872b5Smrg * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
4349f872b5Smrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
4449f872b5Smrg * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
4549f872b5Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
4649f872b5Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
4749f872b5Smrg * OTHER DEALINGS IN THE SOFTWARE.
4849f872b5Smrg *
4949f872b5Smrg */
504f5e7dd7Smrg
514f5e7dd7Smrg/**
524f5e7dd7Smrg * \file pciaccess.h
53cad31331Smrg *
544f5e7dd7Smrg * \author Ian Romanick <idr@us.ibm.com>
554f5e7dd7Smrg */
564f5e7dd7Smrg
574f5e7dd7Smrg#ifndef PCIACCESS_H
584f5e7dd7Smrg#define PCIACCESS_H
594f5e7dd7Smrg
604f5e7dd7Smrg#include <inttypes.h>
614f5e7dd7Smrg
626a94483fSmrg#if (__GNUC__ >= 3) || (__SUNPRO_C >= 0x5130)
634f5e7dd7Smrg#define __deprecated __attribute__((deprecated))
644f5e7dd7Smrg#else
65cad31331Smrg#define __deprecated
664f5e7dd7Smrg#endif
674f5e7dd7Smrg
684f5e7dd7Smrgtypedef uint64_t pciaddr_t;
694f5e7dd7Smrg
704f5e7dd7Smrgstruct pci_device;
714f5e7dd7Smrgstruct pci_device_iterator;
724f5e7dd7Smrgstruct pci_id_match;
734f5e7dd7Smrgstruct pci_slot_match;
744f5e7dd7Smrg
754f5e7dd7Smrg#ifdef __cplusplus
764f5e7dd7Smrgextern "C" {
774f5e7dd7Smrg#endif
784f5e7dd7Smrg
7949f872b5Smrgint pci_device_has_kernel_driver(struct pci_device *dev);
8049f872b5Smrg
8149f872b5Smrgint pci_device_is_boot_vga(struct pci_device *dev);
8249f872b5Smrg
834f5e7dd7Smrgint pci_device_read_rom(struct pci_device *dev, void *buffer);
844f5e7dd7Smrg
854f5e7dd7Smrgint  __deprecated pci_device_map_region(struct pci_device *dev,
864f5e7dd7Smrg    unsigned region, int write_enable);
874f5e7dd7Smrg
884f5e7dd7Smrgint __deprecated pci_device_unmap_region(struct pci_device *dev,
894f5e7dd7Smrg    unsigned region);
904f5e7dd7Smrg
914f5e7dd7Smrgint pci_device_map_range(struct pci_device *dev, pciaddr_t base,
924f5e7dd7Smrg    pciaddr_t size, unsigned map_flags, void **addr);
934f5e7dd7Smrg
944f5e7dd7Smrgint pci_device_unmap_range(struct pci_device *dev, void *memory,
954f5e7dd7Smrg    pciaddr_t size);
964f5e7dd7Smrg
974f5e7dd7Smrgint __deprecated pci_device_map_memory_range(struct pci_device *dev,
984f5e7dd7Smrg    pciaddr_t base, pciaddr_t size, int write_enable, void **addr);
994f5e7dd7Smrg
1004f5e7dd7Smrgint __deprecated pci_device_unmap_memory_range(struct pci_device *dev,
1014f5e7dd7Smrg    void *memory, pciaddr_t size);
1024f5e7dd7Smrg
1034f5e7dd7Smrgint pci_device_probe(struct pci_device *dev);
1044f5e7dd7Smrg
1054f5e7dd7Smrgconst struct pci_agp_info *pci_device_get_agp_info(struct pci_device *dev);
1064f5e7dd7Smrg
1074f5e7dd7Smrgconst struct pci_bridge_info *pci_device_get_bridge_info(
1084f5e7dd7Smrg    struct pci_device *dev);
1094f5e7dd7Smrg
1104f5e7dd7Smrgconst struct pci_pcmcia_bridge_info *pci_device_get_pcmcia_bridge_info(
1114f5e7dd7Smrg    struct pci_device *dev);
1124f5e7dd7Smrg
1134f5e7dd7Smrgint pci_device_get_bridge_buses(struct pci_device *dev, int *primary_bus,
1144f5e7dd7Smrg    int *secondary_bus, int *subordinate_bus);
1154f5e7dd7Smrg
1164f5e7dd7Smrgint pci_system_init(void);
1174f5e7dd7Smrg
1184f5e7dd7Smrgvoid pci_system_init_dev_mem(int fd);
1194f5e7dd7Smrg
1204f5e7dd7Smrgvoid pci_system_cleanup(void);
1214f5e7dd7Smrg
1224f5e7dd7Smrgstruct pci_device_iterator *pci_slot_match_iterator_create(
1234f5e7dd7Smrg    const struct pci_slot_match *match);
1244f5e7dd7Smrg
1254f5e7dd7Smrgstruct pci_device_iterator *pci_id_match_iterator_create(
1264f5e7dd7Smrg    const struct pci_id_match *match);
1274f5e7dd7Smrg
1284f5e7dd7Smrgvoid pci_iterator_destroy(struct pci_device_iterator *iter);
1294f5e7dd7Smrg
1304f5e7dd7Smrgstruct pci_device *pci_device_next(struct pci_device_iterator *iter);
1314f5e7dd7Smrg
1324f5e7dd7Smrgstruct pci_device *pci_device_find_by_slot(uint32_t domain, uint32_t bus,
1334f5e7dd7Smrg    uint32_t dev, uint32_t func);
1344f5e7dd7Smrg
135e432255dSmrgstruct pci_device *pci_device_get_parent_bridge(struct pci_device *dev);
136e432255dSmrg
1374f5e7dd7Smrgvoid pci_get_strings(const struct pci_id_match *m,
1384f5e7dd7Smrg    const char **device_name, const char **vendor_name,
1394f5e7dd7Smrg    const char **subdevice_name, const char **subvendor_name);
1404f5e7dd7Smrgconst char *pci_device_get_device_name(const struct pci_device *dev);
1414f5e7dd7Smrgconst char *pci_device_get_subdevice_name(const struct pci_device *dev);
1424f5e7dd7Smrgconst char *pci_device_get_vendor_name(const struct pci_device *dev);
1434f5e7dd7Smrgconst char *pci_device_get_subvendor_name(const struct pci_device *dev);
1444f5e7dd7Smrg
1454f5e7dd7Smrgvoid pci_device_enable(struct pci_device *dev);
14648becaf0Smrgvoid pci_device_disable(struct pci_device *dev);
1474f5e7dd7Smrg
1484f5e7dd7Smrgint pci_device_cfg_read    (struct pci_device *dev, void *data,
1494f5e7dd7Smrg    pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read);
1504f5e7dd7Smrgint pci_device_cfg_read_u8 (struct pci_device *dev, uint8_t  *data,
1514f5e7dd7Smrg    pciaddr_t offset);
1524f5e7dd7Smrgint pci_device_cfg_read_u16(struct pci_device *dev, uint16_t *data,
1534f5e7dd7Smrg    pciaddr_t offset);
1544f5e7dd7Smrgint pci_device_cfg_read_u32(struct pci_device *dev, uint32_t *data,
1554f5e7dd7Smrg    pciaddr_t offset);
1564f5e7dd7Smrg
1574f5e7dd7Smrgint pci_device_cfg_write    (struct pci_device *dev, const void *data,
1584f5e7dd7Smrg    pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written);
1594f5e7dd7Smrgint pci_device_cfg_write_u8 (struct pci_device *dev, uint8_t  data,
1604f5e7dd7Smrg    pciaddr_t offset);
1614f5e7dd7Smrgint pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
1624f5e7dd7Smrg    pciaddr_t offset);
1634f5e7dd7Smrgint pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
1644f5e7dd7Smrg    pciaddr_t offset);
1654f5e7dd7Smrgint pci_device_cfg_write_bits(struct pci_device *dev, uint32_t mask,
1664f5e7dd7Smrg    uint32_t data, pciaddr_t offset);
1674f5e7dd7Smrg
1684f5e7dd7Smrg#ifdef __cplusplus
1694f5e7dd7Smrg}
1704f5e7dd7Smrg#endif
1714f5e7dd7Smrg
1724f5e7dd7Smrg/**
1734f5e7dd7Smrg * \name Mapping flags passed to \c pci_device_map_range
1744f5e7dd7Smrg */
1754f5e7dd7Smrg/*@{*/
1764f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_WRITABLE       (1U<<0)
1774f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_WRITE_COMBINE  (1U<<1)
1784f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_CACHABLE       (1U<<2)
1794f5e7dd7Smrg/*@}*/
1804f5e7dd7Smrg
1814f5e7dd7Smrg
18286ea1d58Smrg#define PCI_MATCH_ANY  (~0U)
1834f5e7dd7Smrg
1844f5e7dd7Smrg/**
1854f5e7dd7Smrg * Compare two PCI ID values (either vendor or device).  This is used
1864f5e7dd7Smrg * internally to compare the fields of \c pci_id_match to the fields of
1874f5e7dd7Smrg * \c pci_device.
1884f5e7dd7Smrg */
1894f5e7dd7Smrg#define PCI_ID_COMPARE(a, b) \
1904f5e7dd7Smrg    (((a) == PCI_MATCH_ANY) || ((a) == (b)))
1914f5e7dd7Smrg
1924f5e7dd7Smrg/**
1934f5e7dd7Smrg */
1944f5e7dd7Smrgstruct pci_id_match {
1954f5e7dd7Smrg    /**
1964f5e7dd7Smrg     * \name Device / vendor matching controls
197cad31331Smrg     *
1984f5e7dd7Smrg     * Control the search based on the device, vendor, subdevice, or subvendor
1994f5e7dd7Smrg     * IDs.  Setting any of these fields to \c PCI_MATCH_ANY will cause the
2004f5e7dd7Smrg     * field to not be used in the comparison.
2014f5e7dd7Smrg     */
2024f5e7dd7Smrg    /*@{*/
2034f5e7dd7Smrg    uint32_t    vendor_id;
2044f5e7dd7Smrg    uint32_t    device_id;
2054f5e7dd7Smrg    uint32_t    subvendor_id;
2064f5e7dd7Smrg    uint32_t    subdevice_id;
2074f5e7dd7Smrg    /*@}*/
2084f5e7dd7Smrg
2094f5e7dd7Smrg
2104f5e7dd7Smrg    /**
2114f5e7dd7Smrg     * \name Device class matching controls
212cad31331Smrg     *
2134f5e7dd7Smrg     */
2144f5e7dd7Smrg    /*@{*/
2154f5e7dd7Smrg    uint32_t    device_class;
2164f5e7dd7Smrg    uint32_t    device_class_mask;
2174f5e7dd7Smrg    /*@}*/
2184f5e7dd7Smrg
2194f5e7dd7Smrg    intptr_t    match_data;
2204f5e7dd7Smrg};
2214f5e7dd7Smrg
2224f5e7dd7Smrg
2234f5e7dd7Smrg/**
2244f5e7dd7Smrg */
2254f5e7dd7Smrgstruct pci_slot_match {
2264f5e7dd7Smrg    /**
2274f5e7dd7Smrg     * \name Device slot matching controls
2284f5e7dd7Smrg     *
2294f5e7dd7Smrg     * Control the search based on the domain, bus, slot, and function of
2304f5e7dd7Smrg     * the device.  Setting any of these fields to \c PCI_MATCH_ANY will cause
2314f5e7dd7Smrg     * the field to not be used in the comparison.
2324f5e7dd7Smrg     */
2334f5e7dd7Smrg    /*@{*/
2344f5e7dd7Smrg    uint32_t    domain;
2354f5e7dd7Smrg    uint32_t    bus;
2364f5e7dd7Smrg    uint32_t    dev;
2374f5e7dd7Smrg    uint32_t    func;
2384f5e7dd7Smrg    /*@}*/
2394f5e7dd7Smrg
2404f5e7dd7Smrg    intptr_t    match_data;
2414f5e7dd7Smrg};
2424f5e7dd7Smrg
2434f5e7dd7Smrg/**
2444f5e7dd7Smrg * BAR descriptor for a PCI device.
2454f5e7dd7Smrg */
2464f5e7dd7Smrgstruct pci_mem_region {
2474f5e7dd7Smrg    /**
2484f5e7dd7Smrg     * When the region is mapped, this is the pointer to the memory.
2494f5e7dd7Smrg     *
2504f5e7dd7Smrg     * This field is \b only set when the deprecated \c pci_device_map_region
2514f5e7dd7Smrg     * interface is used.  Use \c pci_device_map_range instead.
2524f5e7dd7Smrg     *
2534f5e7dd7Smrg     * \deprecated
2544f5e7dd7Smrg     */
2554f5e7dd7Smrg    void *memory;
2564f5e7dd7Smrg
2574f5e7dd7Smrg
2584f5e7dd7Smrg    /**
2594f5e7dd7Smrg     * Base physical address of the region within its bus / domain.
2604f5e7dd7Smrg     *
2614f5e7dd7Smrg     * \warning
2624f5e7dd7Smrg     * This address is really only useful to other devices in the same
2634f5e7dd7Smrg     * domain.  It's probably \b not the address applications will ever
2644f5e7dd7Smrg     * use.
265cad31331Smrg     *
2664f5e7dd7Smrg     * \warning
2674f5e7dd7Smrg     * Most (all?) platform back-ends leave this field unset.
2684f5e7dd7Smrg     */
2694f5e7dd7Smrg    pciaddr_t bus_addr;
2704f5e7dd7Smrg
2714f5e7dd7Smrg
2724f5e7dd7Smrg    /**
2734f5e7dd7Smrg     * Base physical address of the region from the CPU's point of view.
274cad31331Smrg     *
2754f5e7dd7Smrg     * This address is typically passed to \c pci_device_map_range to create
2764f5e7dd7Smrg     * a mapping of the region to the CPU's virtual address space.
2774f5e7dd7Smrg     */
2784f5e7dd7Smrg    pciaddr_t base_addr;
2794f5e7dd7Smrg
2804f5e7dd7Smrg
2814f5e7dd7Smrg    /**
2824f5e7dd7Smrg     * Size, in bytes, of the region.
2834f5e7dd7Smrg     */
2844f5e7dd7Smrg    pciaddr_t size;
2854f5e7dd7Smrg
2864f5e7dd7Smrg
2874f5e7dd7Smrg    /**
2884f5e7dd7Smrg     * Is the region I/O ports or memory?
2894f5e7dd7Smrg     */
2904f5e7dd7Smrg    unsigned is_IO:1;
2914f5e7dd7Smrg
2924f5e7dd7Smrg    /**
2934f5e7dd7Smrg     * Is the memory region prefetchable?
2944f5e7dd7Smrg     *
2954f5e7dd7Smrg     * \note
2964f5e7dd7Smrg     * This can only be set if \c is_IO is not set.
2974f5e7dd7Smrg     */
2984f5e7dd7Smrg    unsigned is_prefetchable:1;
2994f5e7dd7Smrg
3004f5e7dd7Smrg
3014f5e7dd7Smrg    /**
3024f5e7dd7Smrg     * Is the memory at a 64-bit address?
3034f5e7dd7Smrg     *
3044f5e7dd7Smrg     * \note
3054f5e7dd7Smrg     * This can only be set if \c is_IO is not set.
3064f5e7dd7Smrg     */
3074f5e7dd7Smrg    unsigned is_64:1;
3084f5e7dd7Smrg};
3094f5e7dd7Smrg
3104f5e7dd7Smrg
3114f5e7dd7Smrg/**
3124f5e7dd7Smrg * PCI device.
3134f5e7dd7Smrg *
3144f5e7dd7Smrg * Contains all of the information about a particular PCI device.
31566337f63Smrg *
31666337f63Smrg * This structure - like everything else in libpciaccess - is allocated
31766337f63Smrg * by the library itself. Do not embed this structure in other structs,
31866337f63Smrg * or otherwise allocate them yourself.
3194f5e7dd7Smrg */
3204f5e7dd7Smrgstruct pci_device {
3214f5e7dd7Smrg    /**
3224f5e7dd7Smrg     * \name Device bus identification.
3234f5e7dd7Smrg     *
3244f5e7dd7Smrg     * Complete bus identification, including domain, of the device.  On
3254f5e7dd7Smrg     * platforms that do not support PCI domains (e.g., 32-bit x86 hardware),
3264f5e7dd7Smrg     * the domain will always be zero.
32766337f63Smrg     *
32866337f63Smrg     * The domain_16 field is provided for binary compatibility with older
32966337f63Smrg     * libpciaccess.
3304f5e7dd7Smrg     */
3314f5e7dd7Smrg    /*@{*/
33266337f63Smrg    uint16_t    domain_16;
3334f5e7dd7Smrg    uint8_t     bus;
3344f5e7dd7Smrg    uint8_t     dev;
3354f5e7dd7Smrg    uint8_t     func;
3364f5e7dd7Smrg    /*@}*/
3374f5e7dd7Smrg
3384f5e7dd7Smrg
3394f5e7dd7Smrg    /**
3404f5e7dd7Smrg     * \name Vendor / device ID
3414f5e7dd7Smrg     *
3424f5e7dd7Smrg     * The vendor ID, device ID, and sub-IDs for the device.
3434f5e7dd7Smrg     */
3444f5e7dd7Smrg    /*@{*/
3454f5e7dd7Smrg    uint16_t    vendor_id;
3464f5e7dd7Smrg    uint16_t    device_id;
3474f5e7dd7Smrg    uint16_t    subvendor_id;
3484f5e7dd7Smrg    uint16_t    subdevice_id;
3494f5e7dd7Smrg    /*@}*/
3504f5e7dd7Smrg
3514f5e7dd7Smrg    /**
3524f5e7dd7Smrg     * Device's class, subclass, and programming interface packed into a
3534f5e7dd7Smrg     * single 32-bit value.  The class is at bits [23:16], subclass is at
3544f5e7dd7Smrg     * bits [15:8], and programming interface is at [7:0].
3554f5e7dd7Smrg     */
3564f5e7dd7Smrg    uint32_t    device_class;
3574f5e7dd7Smrg
3584f5e7dd7Smrg
3594f5e7dd7Smrg    /**
3604f5e7dd7Smrg     * Device revision number, as read from the configuration header.
3614f5e7dd7Smrg     */
3624f5e7dd7Smrg    uint8_t     revision;
3634f5e7dd7Smrg
3644f5e7dd7Smrg
3654f5e7dd7Smrg    /**
3664f5e7dd7Smrg     * BAR descriptors for the device.
3674f5e7dd7Smrg     */
3684f5e7dd7Smrg    struct pci_mem_region regions[6];
3694f5e7dd7Smrg
3704f5e7dd7Smrg
3714f5e7dd7Smrg    /**
3724f5e7dd7Smrg     * Size, in bytes, of the device's expansion ROM.
3734f5e7dd7Smrg     */
3744f5e7dd7Smrg    pciaddr_t   rom_size;
3754f5e7dd7Smrg
3764f5e7dd7Smrg
3774f5e7dd7Smrg    /**
3784f5e7dd7Smrg     * IRQ associated with the device.  If there is no IRQ, this value will
3794f5e7dd7Smrg     * be -1.
3804f5e7dd7Smrg     */
3814f5e7dd7Smrg    int irq;
3824f5e7dd7Smrg
3834f5e7dd7Smrg
3844f5e7dd7Smrg    /**
3854f5e7dd7Smrg     * Storage for user data.  Users of the library can store arbitrary
3864f5e7dd7Smrg     * data in this pointer.  The library will not use it for any purpose.
38748becaf0Smrg     * It is the user's responsibility to free this memory before destroying
3884f5e7dd7Smrg     * the \c pci_device structure.
3894f5e7dd7Smrg     */
3904f5e7dd7Smrg    intptr_t user_data;
39149f872b5Smrg
39249f872b5Smrg    /**
39349f872b5Smrg      * Used by the VGA arbiter. Type of resource decoded by the device and
39449f872b5Smrg      * the file descriptor (/dev/vga_arbiter). */
39549f872b5Smrg    int vgaarb_rsrc;
39666337f63Smrg
39766337f63Smrg
39866337f63Smrg    /**
39966337f63Smrg     * PCI domain value (full 32 bits)
40066337f63Smrg     */
40166337f63Smrg    uint32_t    domain;
4024f5e7dd7Smrg};
4034f5e7dd7Smrg
4044f5e7dd7Smrg
4054f5e7dd7Smrg/**
4064f5e7dd7Smrg * Description of the AGP capability of the device.
4074f5e7dd7Smrg *
4084f5e7dd7Smrg * \sa pci_device_get_agp_info
4094f5e7dd7Smrg */
4104f5e7dd7Smrgstruct pci_agp_info {
4114f5e7dd7Smrg    /**
4124f5e7dd7Smrg     * Offset of the AGP registers in the devices configuration register
4134f5e7dd7Smrg     * space.  This is generally used so that the offset of the AGP command
4144f5e7dd7Smrg     * register can be determined.
4154f5e7dd7Smrg     */
4164f5e7dd7Smrg    unsigned    config_offset;
4174f5e7dd7Smrg
4184f5e7dd7Smrg
4194f5e7dd7Smrg    /**
4204f5e7dd7Smrg     * \name AGP major / minor version.
4214f5e7dd7Smrg     */
4224f5e7dd7Smrg    /*@{*/
4234f5e7dd7Smrg    uint8_t	major_version;
4244f5e7dd7Smrg    uint8_t     minor_version;
4254f5e7dd7Smrg    /*@}*/
4264f5e7dd7Smrg
4274f5e7dd7Smrg    /**
4284f5e7dd7Smrg     * Logical OR of the supported AGP rates.  For example, a value of 0x07
4294f5e7dd7Smrg     * means that the device can support 1x, 2x, and 4x.  A value of 0x0c
4304f5e7dd7Smrg     * means that the device can support 8x and 4x.
4314f5e7dd7Smrg     */
4324f5e7dd7Smrg    uint8_t    rates;
4334f5e7dd7Smrg
4344f5e7dd7Smrg    unsigned int    fast_writes:1;  /**< Are fast-writes supported? */
4354f5e7dd7Smrg    unsigned int    addr64:1;
4364f5e7dd7Smrg    unsigned int    htrans:1;
4374f5e7dd7Smrg    unsigned int    gart64:1;
4384f5e7dd7Smrg    unsigned int    coherent:1;
4394f5e7dd7Smrg    unsigned int    sideband:1;     /**< Is side-band addressing supported? */
4404f5e7dd7Smrg    unsigned int    isochronus:1;
4414f5e7dd7Smrg
4424f5e7dd7Smrg    uint8_t    async_req_size;
4434f5e7dd7Smrg    uint8_t    calibration_cycle_timing;
4444f5e7dd7Smrg    uint8_t    max_requests;
4454f5e7dd7Smrg};
4464f5e7dd7Smrg
4474f5e7dd7Smrg/**
4484f5e7dd7Smrg * Description of a PCI-to-PCI bridge device.
4494f5e7dd7Smrg *
4504f5e7dd7Smrg * \sa pci_device_get_bridge_info
4514f5e7dd7Smrg */
4524f5e7dd7Smrgstruct pci_bridge_info {
4534f5e7dd7Smrg    uint8_t    primary_bus;
4544f5e7dd7Smrg    uint8_t    secondary_bus;
4554f5e7dd7Smrg    uint8_t    subordinate_bus;
4564f5e7dd7Smrg    uint8_t    secondary_latency_timer;
4574f5e7dd7Smrg
4584f5e7dd7Smrg    uint8_t     io_type;
4594f5e7dd7Smrg    uint8_t     mem_type;
4604f5e7dd7Smrg    uint8_t     prefetch_mem_type;
4614f5e7dd7Smrg
4624f5e7dd7Smrg    uint16_t    secondary_status;
4634f5e7dd7Smrg    uint16_t    bridge_control;
4644f5e7dd7Smrg
4654f5e7dd7Smrg    uint32_t    io_base;
4664f5e7dd7Smrg    uint32_t    io_limit;
4674f5e7dd7Smrg
4684f5e7dd7Smrg    uint32_t    mem_base;
4694f5e7dd7Smrg    uint32_t    mem_limit;
4704f5e7dd7Smrg
4714f5e7dd7Smrg    uint64_t    prefetch_mem_base;
4724f5e7dd7Smrg    uint64_t    prefetch_mem_limit;
4734f5e7dd7Smrg};
4744f5e7dd7Smrg
4754f5e7dd7Smrg/**
4764f5e7dd7Smrg * Description of a PCI-to-PCMCIA bridge device.
4774f5e7dd7Smrg *
4784f5e7dd7Smrg * \sa pci_device_get_pcmcia_bridge_info
4794f5e7dd7Smrg */
4804f5e7dd7Smrgstruct pci_pcmcia_bridge_info {
4814f5e7dd7Smrg    uint8_t    primary_bus;
4824f5e7dd7Smrg    uint8_t    card_bus;
4834f5e7dd7Smrg    uint8_t    subordinate_bus;
4844f5e7dd7Smrg    uint8_t    cardbus_latency_timer;
485cad31331Smrg
4864f5e7dd7Smrg    uint16_t    secondary_status;
4874f5e7dd7Smrg    uint16_t    bridge_control;
4884f5e7dd7Smrg
4894f5e7dd7Smrg    struct {
4904f5e7dd7Smrg	uint32_t    base;
4914f5e7dd7Smrg	uint32_t    limit;
4924f5e7dd7Smrg    } io[2];
4934f5e7dd7Smrg
4944f5e7dd7Smrg    struct {
4954f5e7dd7Smrg	uint32_t    base;
4964f5e7dd7Smrg	uint32_t    limit;
4974f5e7dd7Smrg    } mem[2];
4984f5e7dd7Smrg
4994f5e7dd7Smrg};
5004f5e7dd7Smrg
50149f872b5Smrg
50249f872b5Smrg/**
50349f872b5Smrg * VGA Arbiter definitions, functions and related.
50449f872b5Smrg */
50549f872b5Smrg
50649f872b5Smrg/* Legacy VGA regions */
50749f872b5Smrg#define VGA_ARB_RSRC_NONE       0x00
50849f872b5Smrg#define VGA_ARB_RSRC_LEGACY_IO  0x01
50949f872b5Smrg#define VGA_ARB_RSRC_LEGACY_MEM 0x02
51049f872b5Smrg/* Non-legacy access */
51149f872b5Smrg#define VGA_ARB_RSRC_NORMAL_IO  0x04
51249f872b5Smrg#define VGA_ARB_RSRC_NORMAL_MEM 0x08
51349f872b5Smrg
51449f872b5Smrgint  pci_device_vgaarb_init         (void);
51549f872b5Smrgvoid pci_device_vgaarb_fini         (void);
51649f872b5Smrgint  pci_device_vgaarb_set_target   (struct pci_device *dev);
51748becaf0Smrg/* use the targeted device */
51849f872b5Smrgint  pci_device_vgaarb_decodes      (int new_vga_rsrc);
51949f872b5Smrgint  pci_device_vgaarb_lock         (void);
52049f872b5Smrgint  pci_device_vgaarb_trylock      (void);
52149f872b5Smrgint  pci_device_vgaarb_unlock       (void);
52249f872b5Smrg/* return the current device count + resource decodes for the device */
52349f872b5Smrgint pci_device_vgaarb_get_info	    (struct pci_device *dev, int *vga_count, int *rsrc_decodes);
52449f872b5Smrg
525e432255dSmrg/*
526e432255dSmrg * I/O space access.
527e432255dSmrg */
528e432255dSmrg
529e432255dSmrgstruct pci_io_handle;
530e432255dSmrg
531e432255dSmrgstruct pci_io_handle *pci_device_open_io(struct pci_device *dev, pciaddr_t base,
532e432255dSmrg					 pciaddr_t size);
533e432255dSmrgstruct pci_io_handle *pci_legacy_open_io(struct pci_device *dev, pciaddr_t base,
534e432255dSmrg					 pciaddr_t size);
535e432255dSmrgvoid pci_device_close_io(struct pci_device *dev, struct pci_io_handle *handle);
536e432255dSmrguint32_t pci_io_read32(struct pci_io_handle *handle, uint32_t reg);
537e432255dSmrguint16_t pci_io_read16(struct pci_io_handle *handle, uint32_t reg);
538e432255dSmrguint8_t pci_io_read8(struct pci_io_handle *handle, uint32_t reg);
539e432255dSmrgvoid pci_io_write32(struct pci_io_handle *handle, uint32_t reg, uint32_t data);
540e432255dSmrgvoid pci_io_write16(struct pci_io_handle *handle, uint32_t reg, uint16_t data);
541e432255dSmrgvoid pci_io_write8(struct pci_io_handle *handle, uint32_t reg, uint8_t data);
542e432255dSmrg
543cad31331Smrg/*
544cad31331Smrg * Legacy memory access
545cad31331Smrg */
546cad31331Smrg
547cad31331Smrgint pci_device_map_legacy(struct pci_device *dev, pciaddr_t base,
548cad31331Smrg			  pciaddr_t size, unsigned map_flags, void **addr);
549cad31331Smrgint pci_device_unmap_legacy(struct pci_device *dev, void *addr, pciaddr_t size);
550cad31331Smrg
5514f5e7dd7Smrg#endif /* PCIACCESS_H */
552