2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2008,2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#ifndef GRUB_PCI_H
2N/A#define GRUB_PCI_H 1
2N/A
2N/A#ifndef ASM_FILE
2N/A#include <grub/types.h>
2N/A#include <grub/symbol.h>
2N/A#endif
2N/A
2N/A#define GRUB_PCI_ADDR_SPACE_MASK 0x01
2N/A#define GRUB_PCI_ADDR_SPACE_MEMORY 0x00
2N/A#define GRUB_PCI_ADDR_SPACE_IO 0x01
2N/A
2N/A#define GRUB_PCI_ADDR_MEM_TYPE_MASK 0x06
2N/A#define GRUB_PCI_ADDR_MEM_TYPE_32 0x00 /* 32 bit address */
2N/A#define GRUB_PCI_ADDR_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */
2N/A#define GRUB_PCI_ADDR_MEM_TYPE_64 0x04 /* 64 bit address */
2N/A#define GRUB_PCI_ADDR_MEM_PREFETCH 0x08 /* prefetchable */
2N/A
2N/A#define GRUB_PCI_ADDR_MEM_MASK ~0xf
2N/A#define GRUB_PCI_ADDR_IO_MASK ~0x03
2N/A
2N/A#define GRUB_PCI_REG_PCI_ID 0x00
2N/A#define GRUB_PCI_REG_VENDOR 0x00
2N/A#define GRUB_PCI_REG_DEVICE 0x02
2N/A#define GRUB_PCI_REG_COMMAND 0x04
2N/A#define GRUB_PCI_REG_STATUS 0x06
2N/A#define GRUB_PCI_REG_REVISION 0x08
2N/A#define GRUB_PCI_REG_CLASS 0x08
2N/A#define GRUB_PCI_REG_CACHELINE 0x0c
2N/A#define GRUB_PCI_REG_LAT_TIMER 0x0d
2N/A#define GRUB_PCI_REG_HEADER_TYPE 0x0e
2N/A#define GRUB_PCI_REG_BIST 0x0f
2N/A#define GRUB_PCI_REG_ADDRESSES 0x10
2N/A
2N/A/* Beware that 64-bit address takes 2 registers. */
2N/A#define GRUB_PCI_REG_ADDRESS_REG0 0x10
2N/A#define GRUB_PCI_REG_ADDRESS_REG1 0x14
2N/A#define GRUB_PCI_REG_ADDRESS_REG2 0x18
2N/A#define GRUB_PCI_REG_ADDRESS_REG3 0x1c
2N/A#define GRUB_PCI_REG_ADDRESS_REG4 0x20
2N/A#define GRUB_PCI_REG_ADDRESS_REG5 0x24
2N/A
2N/A#define GRUB_PCI_REG_CIS_POINTER 0x28
2N/A#define GRUB_PCI_REG_SUBVENDOR 0x2c
2N/A#define GRUB_PCI_REG_SUBSYSTEM 0x2e
2N/A#define GRUB_PCI_REG_ROM_ADDRESS 0x30
2N/A#define GRUB_PCI_REG_CAP_POINTER 0x34
2N/A#define GRUB_PCI_REG_IRQ_LINE 0x3c
2N/A#define GRUB_PCI_REG_IRQ_PIN 0x3d
2N/A#define GRUB_PCI_REG_MIN_GNT 0x3e
2N/A#define GRUB_PCI_REG_MAX_LAT 0x3f
2N/A
2N/A#define GRUB_PCI_COMMAND_IO_ENABLED 0x0001
2N/A#define GRUB_PCI_COMMAND_MEM_ENABLED 0x0002
2N/A#define GRUB_PCI_COMMAND_BUS_MASTER 0x0004
2N/A#define GRUB_PCI_COMMAND_PARITY_ERROR 0x0040
2N/A#define GRUB_PCI_COMMAND_SERR_ENABLE 0x0100
2N/A
2N/A#define GRUB_PCI_STATUS_CAPABILITIES 0x0010
2N/A#define GRUB_PCI_STATUS_66MHZ_CAPABLE 0x0020
2N/A#define GRUB_PCI_STATUS_FAST_B2B_CAPABLE 0x0080
2N/A
2N/A#define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
2N/A#define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
2N/A#define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300
2N/A
2N/A#ifndef ASM_FILE
2N/Atypedef grub_uint32_t grub_pci_id_t;
2N/A
2N/A#ifdef GRUB_MACHINE_EMU
2N/A#include <grub/pciutils.h>
2N/A#else
2N/Atypedef grub_uint32_t grub_pci_address_t;
2N/Astruct grub_pci_device
2N/A{
2N/A int bus;
2N/A int device;
2N/A int function;
2N/A};
2N/Atypedef struct grub_pci_device grub_pci_device_t;
2N/Astatic inline int
2N/Agrub_pci_get_bus (grub_pci_device_t dev)
2N/A{
2N/A return dev.bus;
2N/A}
2N/A
2N/Astatic inline int
2N/Agrub_pci_get_device (grub_pci_device_t dev)
2N/A{
2N/A return dev.device;
2N/A}
2N/A
2N/Astatic inline int
2N/Agrub_pci_get_function (grub_pci_device_t dev)
2N/A{
2N/A return dev.function;
2N/A}
2N/A#include <grub/cpu/pci.h>
2N/A#endif
2N/A
2N/Atypedef int NESTED_FUNC_ATTR (*grub_pci_iteratefunc_t)
2N/A (grub_pci_device_t dev, grub_pci_id_t pciid);
2N/A
2N/Agrub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev,
2N/A int reg);
2N/A
2N/Avoid EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook);
2N/A
2N/Astruct grub_pci_dma_chunk;
2N/A
2N/Astruct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align,
2N/A grub_size_t size);
2N/Avoid EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch);
2N/Avolatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch);
2N/Agrub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch);
2N/A
2N/A#endif
2N/A
2N/A#endif /* GRUB_PCI_H */