#include "devices/pci.h"
#include "threads/malloc.h"
#include "threads/interrupt.h"
#include "threads/pte.h"
#include "threads/io.h"
#include "pci_lookup.h"
#include <round.h>
#include <list.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | pci_config_header |
struct | pci_dev |
struct | pci_io |
Defines | |
#define | PCI_TRANSLATION_ENABLE 1 |
#define | PCI_REG_ADDR 0xcf8 |
#define | PCI_REG_DATA 0xcfc |
#define | pci_config_offset(bus, dev, func, reg) (0x80000000 | ((bus) << 16) | ((dev) << 11) | ((func) << 8) | (reg & (~3))) |
#define | PCI_MAX_DEV_PER_BUS 32 |
#define | PCI_MAX_FUNC_PER_DEV 8 |
#define | PCI_HEADER_SZ 256 |
#define | PCI_CMD_IO 0x001 |
#define | PCI_CMD_MEMORY 0x002 |
#define | PCI_CMD_MASTER 0x004 |
#define | PCI_CMD_SPECIAL 0x008 |
#define | PCI_CMD_INVALIDATE 0x010 |
#define | PCI_CMD_PALETTE 0x020 |
#define | PCI_CMD_PARITY 0x040 |
#define | PCI_CMD_WAIT 0x080 |
#define | PCI_CMD_SERR 0x100 |
#define | PCI_CMD_FASTBACK 0x200 |
#define | PCI_CMD_INTX_DISABLE 0x400 |
#define | PCI_STATUS_CAPLIST 0x10 |
#define | PCI_STATUS_66MHZ 0x20 |
#define | PCI_STATUS_UDF 0x40 |
#define | PCI_STATUS_FASTBACK 0x80 |
#define | PCI_STATUS_PARITY 0x100 |
#define | PCI_STATUS_DEVSEL 0x600 |
#define | PCI_STATUS_DEVSEL_FAST 0 |
#define | PCI_STATUS_DEVSEL_MED 0x200 |
#define | PCI_STATUS_DEVSEL_SLOW 0x400 |
#define | PCI_STATUS_SIG_ABORT 0x0800 |
#define | PCI_STATUS_REC_ABORT 0x1000 |
#define | PCI_STATUS_REC_ABORT_M 0x2000 |
#define | PCI_STATUS_SERR 0x4000 |
#define | PCI_STATUS_PARITY2 0x8000 |
#define | PCI_HEADER_NORMAL 0 |
#define | PCI_HEADER_BRIDGE 1 |
#define | PCI_HEADER_CARDBUS 2 |
#define | PCI_HEADER_MASK 0x7f |
#define | PCI_HEADER_MULTIFUNC 0x80 |
#define | pci_get_reg_offset(x) (&(((pci_config_header*)(NULL))->x)) |
#define | PCI_VENDOR_INVALID 0xffff |
#define | PCI_BASEADDR_IO 0x00000001 |
#define | PCI_BASEADDR_TYPEMASK 0x00000006 |
#define | PCI_BASEADDR_32BIT 0x00000000 |
#define | PCI_BASEADDR_64BIT 0x00000004 |
#define | PCI_BASEADDR_PREFETCH 0x00000008 |
#define | PCI_BASEADDR_ADDR32 0xfffffff0 |
#define | PCI_BASEADDR_ADDR64 0xfffffffffffffff0 |
#define | PCI_BASEADDR_IOPORT 0xfffffffc |
#define | PCI_BASE_COUNT 6 |
Enumerations | |
enum | pci_io_type { PCI_IO_MEM, PCI_IO_PORT } |
Functions | |
static void | pci_write_config (int bus, int dev, int func, int reg, int size, uint32_t data) |
static uint32_t | pci_read_config (int bus, int dev, int func, int reg, int size) |
static void | pci_read_all_config (int bus, int dev, int func, struct pci_config_header *pch) |
static int | pci_scan_bus (int bus) |
static int | pci_probe (int bus, int dev, int func, struct pci_config_header *ph) |
static int | pci_pci_bridge (struct pci_dev *pd) |
static void | pci_power_on (struct pci_dev *pd) |
static void | pci_setup_io (struct pci_dev *pd) |
static void | pci_interrupt (struct intr_frame *) |
static void | pci_print_dev_info (struct pci_dev *pd) |
static void * | pci_alloc_mem (void *phys_ptr, int pages) |
void | pci_init (void) |
struct pci_dev * | pci_get_device (int vendor, int device, int func, int n) |
struct pci_dev * | pci_get_dev_by_class (int major, int minor, int iface, int n) |
struct pci_io * | pci_io_enum (struct pci_dev *pio, struct pci_io *last) |
void | pci_register_irq (struct pci_dev *pd, pci_handler_func *f, void *aux) |
void | pci_unregister_irq (struct pci_dev *pd) |
size_t | pci_io_size (struct pci_io *pio) |
void | pci_reg_write32 (struct pci_io *pio, int reg, uint32_t data) |
void | pci_reg_write16 (struct pci_io *pio, int reg, uint16_t data) |
void | pci_reg_write8 (struct pci_io *pio, int reg, uint8_t data) |
uint32_t | pci_reg_read32 (struct pci_io *pio, int reg) |
uint16_t | pci_reg_read16 (struct pci_io *pio, int reg) |
uint8_t | pci_reg_read8 (struct pci_io *pio, int reg) |
void | pci_read_in (struct pci_io *pio UNUSED, int off UNUSED, size_t size UNUSED, void *buf UNUSED) |
void | pci_write_out (struct pci_io *pio UNUSED, int off UNUSED, size_t size UNUSED, const void *buf UNUSED) |
static void | pci_power_on (struct pci_dev *pd UNUSED) |
void | pci_print_stats (void) |
void | pci_mask_irq (struct pci_dev *pd) |
void | pci_unmask_irq (struct pci_dev *pd) |
void | pci_write_config16 (struct pci_dev *pd, int off, uint16_t data) |
void | pci_write_config32 (struct pci_dev *pd, int off, uint32_t data) |
void | pci_write_config8 (struct pci_dev *pd, int off, uint8_t data) |
uint8_t | pci_read_config8 (struct pci_dev *pd, int off) |
uint16_t | pci_read_config16 (struct pci_dev *pd, int off) |
uint32_t | pci_read_config32 (struct pci_dev *pd, int off) |
Variables | |
uint32_t * | base_page_dir |
static struct list | devices |
static struct list | int_devices |
static int | num_pci_pages |
#define PCI_BASE_COUNT 6 |
#define PCI_BASEADDR_IO 0x00000001 |
#define pci_config_offset | ( | bus, | |||
dev, | |||||
func, | |||||
reg | ) | (0x80000000 | ((bus) << 16) | ((dev) << 11) | ((func) << 8) | (reg & (~3))) |
#define pci_get_reg_offset | ( | x | ) | (&(((pci_config_header*)(NULL))->x)) |
#define PCI_HEADER_MULTIFUNC 0x80 |
#define PCI_MAX_DEV_PER_BUS 32 |
#define PCI_REG_ADDR 0xcf8 |
#define PCI_REG_DATA 0xcfc |
#define PCI_VENDOR_INVALID 0xffff |
enum pci_io_type |
static void * pci_alloc_mem | ( | void * | phys_ptr, | |
int | pages | |||
) | [static] |
allocate PCI memory pages for PCI devices
Definition at line 781 of file pci.c.
References base_page_dir, NULL, num_pci_pages, PCI_ADDR_ZONE_BEGIN, PCI_ADDR_ZONE_PAGES, pd_no(), PGMASK, PGSIZE, PTE_CD, PTE_P, PTE_W, and ptov().
Referenced by pci_setup_io().
struct pci_dev* pci_get_dev_by_class | ( | int | major, | |
int | minor, | |||
int | iface, | |||
int | n | |||
) | [read] |
Definition at line 206 of file pci.c.
References devices, list_begin(), list_end(), list_entry, list_next(), NULL, pci_dev::pch, pci_config_header::pci_interface, pci_config_header::pci_major, pci_config_header::pci_minor, and pci_dev::peer.
Referenced by ehci_init(), and uhci_init().
struct pci_dev* pci_get_device | ( | int | vendor, | |
int | device, | |||
int | func, | |||
int | n | |||
) | [read] |
Definition at line 179 of file pci.c.
References devices, pci_dev::func, list_begin(), list_end(), list_entry, list_next(), NULL, pci_dev::pch, pci_config_header::pci_device_id, pci_config_header::pci_vendor_id, and pci_dev::peer.
void pci_init | ( | void | ) |
Definition at line 167 of file pci.c.
References devices, int_devices, list_init(), num_pci_pages, pci_print_stats(), and pci_scan_bus().
Referenced by main().
static void pci_interrupt | ( | struct intr_frame * | frame | ) | [static] |
Definition at line 681 of file pci.c.
References int_devices, pci_dev::int_peer, pci_dev::irq_handler, pci_dev::irq_handler_aux, list_begin(), list_end(), list_entry, list_next(), pci_dev::pch, pci_config_header::pci_int_line, and intr_frame::vec_no.
Referenced by pci_register_irq().
Definition at line 234 of file pci.c.
References pci_dev::io_ranges, list_begin(), list_end(), list_entry, list_next(), NULL, and pci_io::peer.
Referenced by ehci_init(), and uhci_init().
Definition at line 281 of file pci.c.
References ASSERT, NULL, and pci_io::size.
Referenced by uhci_init().
void pci_mask_irq | ( | struct pci_dev * | pd | ) |
Definition at line 731 of file pci.c.
References intr_irq_mask(), pci_dev::pch, and pci_config_header::pci_int_line.
static int pci_pci_bridge | ( | struct pci_dev * | pd | ) | [static] |
Definition at line 642 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, offsetof, pci_dev::pch, pci_config_header::pci_command, pci_scan_bus(), and pci_write_config().
Referenced by pci_probe().
static void pci_power_on | ( | struct pci_dev *pd | UNUSED | ) | [static] |
static void pci_power_on | ( | struct pci_dev * | pd | ) | [static] |
Referenced by pci_probe().
static void pci_print_dev_info | ( | struct pci_dev * | pd | ) | [static] |
Definition at line 718 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, pci_dev::pch, pci_config_header::pci_device_id, pci_config_header::pci_int_line, pci_config_header::pci_interface, pci_lookup_class(), pci_lookup_device, pci_lookup_vendor, pci_config_header::pci_major, pci_config_header::pci_minor, pci_config_header::pci_vendor_id, and printf().
Referenced by pci_print_stats().
void pci_print_stats | ( | void | ) |
Definition at line 701 of file pci.c.
References devices, list_begin(), list_end(), list_entry, list_next(), pci_print_dev_info(), and pci_dev::peer.
Referenced by pci_init().
static int pci_probe | ( | int | bus, | |
int | dev, | |||
int | func, | |||
struct pci_config_header * | ph | |||
) | [static] |
Definition at line 533 of file pci.c.
References pci_dev::bus, pci_dev::dev, devices, pci_dev::func, pci_dev::io_ranges, pci_dev::irq_handler, pci_dev::irq_handler_aux, list_init(), list_push_back(), malloc(), memcpy(), NULL, pci_dev::pch, pci_config_header::pci_major, PCI_MAJOR_BRIDGE, pci_config_header::pci_minor, PCI_MINOR_PCI, pci_pci_bridge(), pci_power_on(), pci_read_all_config(), pci_setup_io(), pci_config_header::pci_vendor_id, PCI_VENDOR_INVALID, and pci_dev::peer.
Referenced by pci_scan_bus().
static void pci_read_all_config | ( | int | bus, | |
int | dev, | |||
int | func, | |||
struct pci_config_header * | pch | |||
) | [static] |
Definition at line 480 of file pci.c.
References pci_read_config().
Referenced by pci_probe(), and pci_scan_bus().
static uint32_t pci_read_config | ( | int | bus, | |
int | dev, | |||
int | func, | |||
int | reg, | |||
int | size | |||
) | [static] |
Definition at line 451 of file pci.c.
References inb(), inl(), inw(), outl(), PANIC, pci_config_offset, PCI_REG_ADDR, and PCI_REG_DATA.
Referenced by pci_read_all_config(), pci_read_config16(), pci_read_config32(), pci_read_config8(), and pci_setup_io().
Definition at line 767 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().
Definition at line 773 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().
Definition at line 761 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().
Definition at line 365 of file pci.c.
References pci_io::addr, ASSERT, inw(), NULL, PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by check_and_flip_change(), dump_regs(), uhci_detect_ports(), uhci_enable_port(), uhci_init(), uhci_irq(), uhci_run_unlocked(), and uhci_stop_unlocked().
Definition at line 343 of file pci.c.
References pci_io::addr, ASSERT, inl(), NULL, PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by dump_regs().
Definition at line 389 of file pci.c.
References pci_io::addr, ASSERT, inb(), NULL, PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by ehci_init().
Definition at line 307 of file pci.c.
References pci_io::addr, ASSERT, NULL, outw(), PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by check_and_flip_change(), uhci_enable_port(), uhci_init(), uhci_irq(), uhci_run_unlocked(), and uhci_stop_unlocked().
Definition at line 289 of file pci.c.
References pci_io::addr, ASSERT, NULL, outl(), PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by ehci_init(), and uhci_init().
Definition at line 325 of file pci.c.
References pci_io::addr, ASSERT, NULL, outb(), PANIC, PCI_IO_MEM, PCI_IO_PORT, pci_io::port, pci_io::ptr, and pci_io::type.
Referenced by uhci_init().
void pci_register_irq | ( | struct pci_dev * | pd, | |
pci_handler_func * | f, | |||
void * | aux | |||
) |
Definition at line 250 of file pci.c.
References ASSERT, int_devices, pci_dev::int_peer, intr_is_registered(), intr_register_ext(), pci_dev::irq_handler, pci_dev::irq_handler_aux, list_push_back(), NULL, pci_dev::pch, pci_config_header::pci_int_line, and pci_interrupt().
Referenced by uhci_init().
static int pci_scan_bus | ( | int | bus | ) | [static] |
scan PCI bus for all devices
Definition at line 493 of file pci.c.
References pci_config_header::pci_header, PCI_HEADER_MULTIFUNC, PCI_MAX_DEV_PER_BUS, pci_probe(), pci_read_all_config(), pci_config_header::pci_vendor_id, and PCI_VENDOR_INVALID.
Referenced by pci_init(), and pci_pci_bridge().
static void pci_setup_io | ( | struct pci_dev * | pd | ) | [static] |
Definition at line 569 of file pci.c.
References pci_io::addr, pci_dev::bus, pci_io::dev, pci_dev::dev, free(), pci_dev::func, pci_dev::io_ranges, list_push_back(), malloc(), NULL, offsetof, pci_dev::pch, pci_alloc_mem(), PCI_BASE_COUNT, pci_config_header::pci_base_reg, PCI_BASEADDR_IO, PCI_IO_MEM, PCI_IO_PORT, pci_read_config(), pci_write_config(), pci_io::peer, PGMASK, PGSIZE, pci_io::port, printf(), pci_io::ptr, ROUND_UP, pci_io::size, and pci_io::type.
Referenced by pci_probe().
void pci_unmask_irq | ( | struct pci_dev * | pd | ) |
Definition at line 737 of file pci.c.
References intr_irq_unmask(), pci_dev::pch, and pci_config_header::pci_int_line.
void pci_unregister_irq | ( | struct pci_dev * | pd | ) |
Definition at line 268 of file pci.c.
References ASSERT, pci_dev::int_peer, intr_disable(), intr_enable(), pci_dev::irq_handler, pci_dev::irq_handler_aux, list_remove(), and NULL.
static void pci_write_config | ( | int | bus, | |
int | dev, | |||
int | func, | |||
int | reg, | |||
int | size, | |||
uint32_t | data | |||
) | [static] |
Definition at line 425 of file pci.c.
References outb(), outl(), outw(), pci_config_offset, PCI_REG_ADDR, and PCI_REG_DATA.
Referenced by pci_pci_bridge(), pci_setup_io(), pci_write_config16(), pci_write_config32(), and pci_write_config8().
Definition at line 743 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_write_config().
Referenced by uhci_init().
Definition at line 749 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_write_config().
Definition at line 755 of file pci.c.
References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_write_config().
Definition at line 44 of file init.c.
Referenced by pagedir_activate(), pagedir_create(), pagedir_destroy(), pagedir_set_page(), paging_init(), pci_alloc_mem(), and pci_zone_init().
Definition at line 160 of file pci.c.
Referenced by pci_get_dev_by_class(), pci_get_device(), pci_init(), pci_print_stats(), and pci_probe().
struct list int_devices [static] |
Definition at line 161 of file pci.c.
Referenced by pci_init(), pci_interrupt(), and pci_register_irq().
int num_pci_pages [static] |