pciaccess.h revision 86ea1d58
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
624f5e7dd7Smrg#if __GNUC__ >= 3
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);
1464f5e7dd7Smrg
1474f5e7dd7Smrgint pci_device_cfg_read    (struct pci_device *dev, void *data,
1484f5e7dd7Smrg    pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_read);
1494f5e7dd7Smrgint pci_device_cfg_read_u8 (struct pci_device *dev, uint8_t  *data,
1504f5e7dd7Smrg    pciaddr_t offset);
1514f5e7dd7Smrgint pci_device_cfg_read_u16(struct pci_device *dev, uint16_t *data,
1524f5e7dd7Smrg    pciaddr_t offset);
1534f5e7dd7Smrgint pci_device_cfg_read_u32(struct pci_device *dev, uint32_t *data,
1544f5e7dd7Smrg    pciaddr_t offset);
1554f5e7dd7Smrg
1564f5e7dd7Smrgint pci_device_cfg_write    (struct pci_device *dev, const void *data,
1574f5e7dd7Smrg    pciaddr_t offset, pciaddr_t size, pciaddr_t *bytes_written);
1584f5e7dd7Smrgint pci_device_cfg_write_u8 (struct pci_device *dev, uint8_t  data,
1594f5e7dd7Smrg    pciaddr_t offset);
1604f5e7dd7Smrgint pci_device_cfg_write_u16(struct pci_device *dev, uint16_t data,
1614f5e7dd7Smrg    pciaddr_t offset);
1624f5e7dd7Smrgint pci_device_cfg_write_u32(struct pci_device *dev, uint32_t data,
1634f5e7dd7Smrg    pciaddr_t offset);
1644f5e7dd7Smrgint pci_device_cfg_write_bits(struct pci_device *dev, uint32_t mask,
1654f5e7dd7Smrg    uint32_t data, pciaddr_t offset);
1664f5e7dd7Smrg
1674f5e7dd7Smrg#ifdef __cplusplus
1684f5e7dd7Smrg}
1694f5e7dd7Smrg#endif
1704f5e7dd7Smrg
1714f5e7dd7Smrg/**
1724f5e7dd7Smrg * \name Mapping flags passed to \c pci_device_map_range
1734f5e7dd7Smrg */
1744f5e7dd7Smrg/*@{*/
1754f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_WRITABLE       (1U<<0)
1764f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_WRITE_COMBINE  (1U<<1)
1774f5e7dd7Smrg#define PCI_DEV_MAP_FLAG_CACHABLE       (1U<<2)
1784f5e7dd7Smrg/*@}*/
1794f5e7dd7Smrg
1804f5e7dd7Smrg
18186ea1d58Smrg#define PCI_MATCH_ANY  (~0U)
1824f5e7dd7Smrg
1834f5e7dd7Smrg/**
1844f5e7dd7Smrg * Compare two PCI ID values (either vendor or device).  This is used
1854f5e7dd7Smrg * internally to compare the fields of \c pci_id_match to the fields of
1864f5e7dd7Smrg * \c pci_device.
1874f5e7dd7Smrg */
1884f5e7dd7Smrg#define PCI_ID_COMPARE(a, b) \
1894f5e7dd7Smrg    (((a) == PCI_MATCH_ANY) || ((a) == (b)))
1904f5e7dd7Smrg
1914f5e7dd7Smrg/**
1924f5e7dd7Smrg */
1934f5e7dd7Smrgstruct pci_id_match {
1944f5e7dd7Smrg    /**
1954f5e7dd7Smrg     * \name Device / vendor matching controls
196cad31331Smrg     *
1974f5e7dd7Smrg     * Control the search based on the device, vendor, subdevice, or subvendor
1984f5e7dd7Smrg     * IDs.  Setting any of these fields to \c PCI_MATCH_ANY will cause the
1994f5e7dd7Smrg     * field to not be used in the comparison.
2004f5e7dd7Smrg     */
2014f5e7dd7Smrg    /*@{*/
2024f5e7dd7Smrg    uint32_t    vendor_id;
2034f5e7dd7Smrg    uint32_t    device_id;
2044f5e7dd7Smrg    uint32_t    subvendor_id;
2054f5e7dd7Smrg    uint32_t    subdevice_id;
2064f5e7dd7Smrg    /*@}*/
2074f5e7dd7Smrg
2084f5e7dd7Smrg
2094f5e7dd7Smrg    /**
2104f5e7dd7Smrg     * \name Device class matching controls
211cad31331Smrg     *
2124f5e7dd7Smrg     */
2134f5e7dd7Smrg    /*@{*/
2144f5e7dd7Smrg    uint32_t    device_class;
2154f5e7dd7Smrg    uint32_t    device_class_mask;
2164f5e7dd7Smrg    /*@}*/
2174f5e7dd7Smrg
2184f5e7dd7Smrg    intptr_t    match_data;
2194f5e7dd7Smrg};
2204f5e7dd7Smrg
2214f5e7dd7Smrg
2224f5e7dd7Smrg/**
2234f5e7dd7Smrg */
2244f5e7dd7Smrgstruct pci_slot_match {
2254f5e7dd7Smrg    /**
2264f5e7dd7Smrg     * \name Device slot matching controls
2274f5e7dd7Smrg     *
2284f5e7dd7Smrg     * Control the search based on the domain, bus, slot, and function of
2294f5e7dd7Smrg     * the device.  Setting any of these fields to \c PCI_MATCH_ANY will cause
2304f5e7dd7Smrg     * the field to not be used in the comparison.
2314f5e7dd7Smrg     */
2324f5e7dd7Smrg    /*@{*/
2334f5e7dd7Smrg    uint32_t    domain;
2344f5e7dd7Smrg    uint32_t    bus;
2354f5e7dd7Smrg    uint32_t    dev;
2364f5e7dd7Smrg    uint32_t    func;
2374f5e7dd7Smrg    /*@}*/
2384f5e7dd7Smrg
2394f5e7dd7Smrg    intptr_t    match_data;
2404f5e7dd7Smrg};
2414f5e7dd7Smrg
2424f5e7dd7Smrg/**
2434f5e7dd7Smrg * BAR descriptor for a PCI device.
2444f5e7dd7Smrg */
2454f5e7dd7Smrgstruct pci_mem_region {
2464f5e7dd7Smrg    /**
2474f5e7dd7Smrg     * When the region is mapped, this is the pointer to the memory.
2484f5e7dd7Smrg     *
2494f5e7dd7Smrg     * This field is \b only set when the deprecated \c pci_device_map_region
2504f5e7dd7Smrg     * interface is used.  Use \c pci_device_map_range instead.
2514f5e7dd7Smrg     *
2524f5e7dd7Smrg     * \deprecated
2534f5e7dd7Smrg     */
2544f5e7dd7Smrg    void *memory;
2554f5e7dd7Smrg
2564f5e7dd7Smrg
2574f5e7dd7Smrg    /**
2584f5e7dd7Smrg     * Base physical address of the region within its bus / domain.
2594f5e7dd7Smrg     *
2604f5e7dd7Smrg     * \warning
2614f5e7dd7Smrg     * This address is really only useful to other devices in the same
2624f5e7dd7Smrg     * domain.  It's probably \b not the address applications will ever
2634f5e7dd7Smrg     * use.
264cad31331Smrg     *
2654f5e7dd7Smrg     * \warning
2664f5e7dd7Smrg     * Most (all?) platform back-ends leave this field unset.
2674f5e7dd7Smrg     */
2684f5e7dd7Smrg    pciaddr_t bus_addr;
2694f5e7dd7Smrg
2704f5e7dd7Smrg
2714f5e7dd7Smrg    /**
2724f5e7dd7Smrg     * Base physical address of the region from the CPU's point of view.
273cad31331Smrg     *
2744f5e7dd7Smrg     * This address is typically passed to \c pci_device_map_range to create
2754f5e7dd7Smrg     * a mapping of the region to the CPU's virtual address space.
2764f5e7dd7Smrg     */
2774f5e7dd7Smrg    pciaddr_t base_addr;
2784f5e7dd7Smrg
2794f5e7dd7Smrg
2804f5e7dd7Smrg    /**
2814f5e7dd7Smrg     * Size, in bytes, of the region.
2824f5e7dd7Smrg     */
2834f5e7dd7Smrg    pciaddr_t size;
2844f5e7dd7Smrg
2854f5e7dd7Smrg
2864f5e7dd7Smrg    /**
2874f5e7dd7Smrg     * Is the region I/O ports or memory?
2884f5e7dd7Smrg     */
2894f5e7dd7Smrg    unsigned is_IO:1;
2904f5e7dd7Smrg
2914f5e7dd7Smrg    /**
2924f5e7dd7Smrg     * Is the memory region prefetchable?
2934f5e7dd7Smrg     *
2944f5e7dd7Smrg     * \note
2954f5e7dd7Smrg     * This can only be set if \c is_IO is not set.
2964f5e7dd7Smrg     */
2974f5e7dd7Smrg    unsigned is_prefetchable:1;
2984f5e7dd7Smrg
2994f5e7dd7Smrg
3004f5e7dd7Smrg    /**
3014f5e7dd7Smrg     * Is the memory at a 64-bit address?
3024f5e7dd7Smrg     *
3034f5e7dd7Smrg     * \note
3044f5e7dd7Smrg     * This can only be set if \c is_IO is not set.
3054f5e7dd7Smrg     */
3064f5e7dd7Smrg    unsigned is_64:1;
3074f5e7dd7Smrg};
3084f5e7dd7Smrg
3094f5e7dd7Smrg
3104f5e7dd7Smrg/**
3114f5e7dd7Smrg * PCI device.
3124f5e7dd7Smrg *
3134f5e7dd7Smrg * Contains all of the information about a particular PCI device.
3144f5e7dd7Smrg */
3154f5e7dd7Smrgstruct pci_device {
3164f5e7dd7Smrg    /**
3174f5e7dd7Smrg     * \name Device bus identification.
3184f5e7dd7Smrg     *
3194f5e7dd7Smrg     * Complete bus identification, including domain, of the device.  On
3204f5e7dd7Smrg     * platforms that do not support PCI domains (e.g., 32-bit x86 hardware),
3214f5e7dd7Smrg     * the domain will always be zero.
3224f5e7dd7Smrg     */
3234f5e7dd7Smrg    /*@{*/
3244f5e7dd7Smrg    uint16_t    domain;
3254f5e7dd7Smrg    uint8_t     bus;
3264f5e7dd7Smrg    uint8_t     dev;
3274f5e7dd7Smrg    uint8_t     func;
3284f5e7dd7Smrg    /*@}*/
3294f5e7dd7Smrg
3304f5e7dd7Smrg
3314f5e7dd7Smrg    /**
3324f5e7dd7Smrg     * \name Vendor / device ID
3334f5e7dd7Smrg     *
3344f5e7dd7Smrg     * The vendor ID, device ID, and sub-IDs for the device.
3354f5e7dd7Smrg     */
3364f5e7dd7Smrg    /*@{*/
3374f5e7dd7Smrg    uint16_t    vendor_id;
3384f5e7dd7Smrg    uint16_t    device_id;
3394f5e7dd7Smrg    uint16_t    subvendor_id;
3404f5e7dd7Smrg    uint16_t    subdevice_id;
3414f5e7dd7Smrg    /*@}*/
3424f5e7dd7Smrg
3434f5e7dd7Smrg    /**
3444f5e7dd7Smrg     * Device's class, subclass, and programming interface packed into a
3454f5e7dd7Smrg     * single 32-bit value.  The class is at bits [23:16], subclass is at
3464f5e7dd7Smrg     * bits [15:8], and programming interface is at [7:0].
3474f5e7dd7Smrg     */
3484f5e7dd7Smrg    uint32_t    device_class;
3494f5e7dd7Smrg
3504f5e7dd7Smrg
3514f5e7dd7Smrg    /**
3524f5e7dd7Smrg     * Device revision number, as read from the configuration header.
3534f5e7dd7Smrg     */
3544f5e7dd7Smrg    uint8_t     revision;
3554f5e7dd7Smrg
3564f5e7dd7Smrg
3574f5e7dd7Smrg    /**
3584f5e7dd7Smrg     * BAR descriptors for the device.
3594f5e7dd7Smrg     */
3604f5e7dd7Smrg    struct pci_mem_region regions[6];
3614f5e7dd7Smrg
3624f5e7dd7Smrg
3634f5e7dd7Smrg    /**
3644f5e7dd7Smrg     * Size, in bytes, of the device's expansion ROM.
3654f5e7dd7Smrg     */
3664f5e7dd7Smrg    pciaddr_t   rom_size;
3674f5e7dd7Smrg
3684f5e7dd7Smrg
3694f5e7dd7Smrg    /**
3704f5e7dd7Smrg     * IRQ associated with the device.  If there is no IRQ, this value will
3714f5e7dd7Smrg     * be -1.
3724f5e7dd7Smrg     */
3734f5e7dd7Smrg    int irq;
3744f5e7dd7Smrg
3754f5e7dd7Smrg
3764f5e7dd7Smrg    /**
3774f5e7dd7Smrg     * Storage for user data.  Users of the library can store arbitrary
3784f5e7dd7Smrg     * data in this pointer.  The library will not use it for any purpose.
3794f5e7dd7Smrg     * It is the user's responsability to free this memory before destroying
3804f5e7dd7Smrg     * the \c pci_device structure.
3814f5e7dd7Smrg     */
3824f5e7dd7Smrg    intptr_t user_data;
38349f872b5Smrg
38449f872b5Smrg    /**
38549f872b5Smrg      * Used by the VGA arbiter. Type of resource decoded by the device and
38649f872b5Smrg      * the file descriptor (/dev/vga_arbiter). */
38749f872b5Smrg    int vgaarb_rsrc;
3884f5e7dd7Smrg};
3894f5e7dd7Smrg
3904f5e7dd7Smrg
3914f5e7dd7Smrg/**
3924f5e7dd7Smrg * Description of the AGP capability of the device.
3934f5e7dd7Smrg *
3944f5e7dd7Smrg * \sa pci_device_get_agp_info
3954f5e7dd7Smrg */
3964f5e7dd7Smrgstruct pci_agp_info {
3974f5e7dd7Smrg    /**
3984f5e7dd7Smrg     * Offset of the AGP registers in the devices configuration register
3994f5e7dd7Smrg     * space.  This is generally used so that the offset of the AGP command
4004f5e7dd7Smrg     * register can be determined.
4014f5e7dd7Smrg     */
4024f5e7dd7Smrg    unsigned    config_offset;
4034f5e7dd7Smrg
4044f5e7dd7Smrg
4054f5e7dd7Smrg    /**
4064f5e7dd7Smrg     * \name AGP major / minor version.
4074f5e7dd7Smrg     */
4084f5e7dd7Smrg    /*@{*/
4094f5e7dd7Smrg    uint8_t	major_version;
4104f5e7dd7Smrg    uint8_t     minor_version;
4114f5e7dd7Smrg    /*@}*/
4124f5e7dd7Smrg
4134f5e7dd7Smrg    /**
4144f5e7dd7Smrg     * Logical OR of the supported AGP rates.  For example, a value of 0x07
4154f5e7dd7Smrg     * means that the device can support 1x, 2x, and 4x.  A value of 0x0c
4164f5e7dd7Smrg     * means that the device can support 8x and 4x.
4174f5e7dd7Smrg     */
4184f5e7dd7Smrg    uint8_t    rates;
4194f5e7dd7Smrg
4204f5e7dd7Smrg    unsigned int    fast_writes:1;  /**< Are fast-writes supported? */
4214f5e7dd7Smrg    unsigned int    addr64:1;
4224f5e7dd7Smrg    unsigned int    htrans:1;
4234f5e7dd7Smrg    unsigned int    gart64:1;
4244f5e7dd7Smrg    unsigned int    coherent:1;
4254f5e7dd7Smrg    unsigned int    sideband:1;     /**< Is side-band addressing supported? */
4264f5e7dd7Smrg    unsigned int    isochronus:1;
4274f5e7dd7Smrg
4284f5e7dd7Smrg    uint8_t    async_req_size;
4294f5e7dd7Smrg    uint8_t    calibration_cycle_timing;
4304f5e7dd7Smrg    uint8_t    max_requests;
4314f5e7dd7Smrg};
4324f5e7dd7Smrg
4334f5e7dd7Smrg/**
4344f5e7dd7Smrg * Description of a PCI-to-PCI bridge device.
4354f5e7dd7Smrg *
4364f5e7dd7Smrg * \sa pci_device_get_bridge_info
4374f5e7dd7Smrg */
4384f5e7dd7Smrgstruct pci_bridge_info {
4394f5e7dd7Smrg    uint8_t    primary_bus;
4404f5e7dd7Smrg    uint8_t    secondary_bus;
4414f5e7dd7Smrg    uint8_t    subordinate_bus;
4424f5e7dd7Smrg    uint8_t    secondary_latency_timer;
4434f5e7dd7Smrg
4444f5e7dd7Smrg    uint8_t     io_type;
4454f5e7dd7Smrg    uint8_t     mem_type;
4464f5e7dd7Smrg    uint8_t     prefetch_mem_type;
4474f5e7dd7Smrg
4484f5e7dd7Smrg    uint16_t    secondary_status;
4494f5e7dd7Smrg    uint16_t    bridge_control;
4504f5e7dd7Smrg
4514f5e7dd7Smrg    uint32_t    io_base;
4524f5e7dd7Smrg    uint32_t    io_limit;
4534f5e7dd7Smrg
4544f5e7dd7Smrg    uint32_t    mem_base;
4554f5e7dd7Smrg    uint32_t    mem_limit;
4564f5e7dd7Smrg
4574f5e7dd7Smrg    uint64_t    prefetch_mem_base;
4584f5e7dd7Smrg    uint64_t    prefetch_mem_limit;
4594f5e7dd7Smrg};
4604f5e7dd7Smrg
4614f5e7dd7Smrg/**
4624f5e7dd7Smrg * Description of a PCI-to-PCMCIA bridge device.
4634f5e7dd7Smrg *
4644f5e7dd7Smrg * \sa pci_device_get_pcmcia_bridge_info
4654f5e7dd7Smrg */
4664f5e7dd7Smrgstruct pci_pcmcia_bridge_info {
4674f5e7dd7Smrg    uint8_t    primary_bus;
4684f5e7dd7Smrg    uint8_t    card_bus;
4694f5e7dd7Smrg    uint8_t    subordinate_bus;
4704f5e7dd7Smrg    uint8_t    cardbus_latency_timer;
471cad31331Smrg
4724f5e7dd7Smrg    uint16_t    secondary_status;
4734f5e7dd7Smrg    uint16_t    bridge_control;
4744f5e7dd7Smrg
4754f5e7dd7Smrg    struct {
4764f5e7dd7Smrg	uint32_t    base;
4774f5e7dd7Smrg	uint32_t    limit;
4784f5e7dd7Smrg    } io[2];
4794f5e7dd7Smrg
4804f5e7dd7Smrg    struct {
4814f5e7dd7Smrg	uint32_t    base;
4824f5e7dd7Smrg	uint32_t    limit;
4834f5e7dd7Smrg    } mem[2];
4844f5e7dd7Smrg
4854f5e7dd7Smrg};
4864f5e7dd7Smrg
48749f872b5Smrg
48849f872b5Smrg/**
48949f872b5Smrg * VGA Arbiter definitions, functions and related.
49049f872b5Smrg */
49149f872b5Smrg
49249f872b5Smrg/* Legacy VGA regions */
49349f872b5Smrg#define VGA_ARB_RSRC_NONE       0x00
49449f872b5Smrg#define VGA_ARB_RSRC_LEGACY_IO  0x01
49549f872b5Smrg#define VGA_ARB_RSRC_LEGACY_MEM 0x02
49649f872b5Smrg/* Non-legacy access */
49749f872b5Smrg#define VGA_ARB_RSRC_NORMAL_IO  0x04
49849f872b5Smrg#define VGA_ARB_RSRC_NORMAL_MEM 0x08
49949f872b5Smrg
50049f872b5Smrgint  pci_device_vgaarb_init         (void);
50149f872b5Smrgvoid pci_device_vgaarb_fini         (void);
50249f872b5Smrgint  pci_device_vgaarb_set_target   (struct pci_device *dev);
50349f872b5Smrg/* use the targetted device */
50449f872b5Smrgint  pci_device_vgaarb_decodes      (int new_vga_rsrc);
50549f872b5Smrgint  pci_device_vgaarb_lock         (void);
50649f872b5Smrgint  pci_device_vgaarb_trylock      (void);
50749f872b5Smrgint  pci_device_vgaarb_unlock       (void);
50849f872b5Smrg/* return the current device count + resource decodes for the device */
50949f872b5Smrgint pci_device_vgaarb_get_info	    (struct pci_device *dev, int *vga_count, int *rsrc_decodes);
51049f872b5Smrg
511e432255dSmrg/*
512e432255dSmrg * I/O space access.
513e432255dSmrg */
514e432255dSmrg
515e432255dSmrgstruct pci_io_handle;
516e432255dSmrg
517e432255dSmrgstruct pci_io_handle *pci_device_open_io(struct pci_device *dev, pciaddr_t base,
518e432255dSmrg					 pciaddr_t size);
519e432255dSmrgstruct pci_io_handle *pci_legacy_open_io(struct pci_device *dev, pciaddr_t base,
520e432255dSmrg					 pciaddr_t size);
521e432255dSmrgvoid pci_device_close_io(struct pci_device *dev, struct pci_io_handle *handle);
522e432255dSmrguint32_t pci_io_read32(struct pci_io_handle *handle, uint32_t reg);
523e432255dSmrguint16_t pci_io_read16(struct pci_io_handle *handle, uint32_t reg);
524e432255dSmrguint8_t pci_io_read8(struct pci_io_handle *handle, uint32_t reg);
525e432255dSmrgvoid pci_io_write32(struct pci_io_handle *handle, uint32_t reg, uint32_t data);
526e432255dSmrgvoid pci_io_write16(struct pci_io_handle *handle, uint32_t reg, uint16_t data);
527e432255dSmrgvoid pci_io_write8(struct pci_io_handle *handle, uint32_t reg, uint8_t data);
528e432255dSmrg
529cad31331Smrg/*
530cad31331Smrg * Legacy memory access
531cad31331Smrg */
532cad31331Smrg
533cad31331Smrgint pci_device_map_legacy(struct pci_device *dev, pciaddr_t base,
534cad31331Smrg			  pciaddr_t size, unsigned map_flags, void **addr);
535cad31331Smrgint pci_device_unmap_legacy(struct pci_device *dev, void *addr, pciaddr_t size);
536cad31331Smrg
5374f5e7dd7Smrg#endif /* PCIACCESS_H */
538