pintos/src/devices/pci.c File Reference

#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_devpci_get_device (int vendor, int device, int func, int n)
struct pci_devpci_get_dev_by_class (int major, int minor, int iface, int n)
struct pci_iopci_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_tbase_page_dir
static struct list devices
static struct list int_devices
static int num_pci_pages


Define Documentation

#define PCI_BASE_COUNT   6

Definition at line 111 of file pci.c.

Referenced by pci_setup_io().

#define PCI_BASEADDR_32BIT   0x00000000

Definition at line 67 of file pci.c.

#define PCI_BASEADDR_64BIT   0x00000004

Definition at line 68 of file pci.c.

#define PCI_BASEADDR_ADDR32   0xfffffff0

Definition at line 70 of file pci.c.

#define PCI_BASEADDR_ADDR64   0xfffffffffffffff0

Definition at line 71 of file pci.c.

#define PCI_BASEADDR_IO   0x00000001

Definition at line 65 of file pci.c.

Referenced by pci_setup_io().

#define PCI_BASEADDR_IOPORT   0xfffffffc

Definition at line 72 of file pci.c.

#define PCI_BASEADDR_PREFETCH   0x00000008

Definition at line 69 of file pci.c.

#define PCI_BASEADDR_TYPEMASK   0x00000006

Definition at line 66 of file pci.c.

#define PCI_CMD_FASTBACK   0x200

Definition at line 36 of file pci.c.

#define PCI_CMD_INTX_DISABLE   0x400

Definition at line 37 of file pci.c.

#define PCI_CMD_INVALIDATE   0x010

Definition at line 31 of file pci.c.

#define PCI_CMD_IO   0x001

Definition at line 27 of file pci.c.

#define PCI_CMD_MASTER   0x004

Definition at line 29 of file pci.c.

#define PCI_CMD_MEMORY   0x002

Definition at line 28 of file pci.c.

#define PCI_CMD_PALETTE   0x020

Definition at line 32 of file pci.c.

#define PCI_CMD_PARITY   0x040

Definition at line 33 of file pci.c.

#define PCI_CMD_SERR   0x100

Definition at line 35 of file pci.c.

#define PCI_CMD_SPECIAL   0x008

Definition at line 30 of file pci.c.

#define PCI_CMD_WAIT   0x080

Definition at line 34 of file pci.c.

#define pci_config_offset ( bus,
dev,
func,
reg   )     (0x80000000 | ((bus) << 16) | ((dev) << 11) | ((func) << 8) | (reg & (~3)))

Definition at line 20 of file pci.c.

Referenced by pci_read_config(), and pci_write_config().

#define pci_get_reg_offset ( x   )     (&(((pci_config_header*)(NULL))->x))

Definition at line 61 of file pci.c.

#define PCI_HEADER_BRIDGE   1

Definition at line 55 of file pci.c.

#define PCI_HEADER_CARDBUS   2

Definition at line 56 of file pci.c.

#define PCI_HEADER_MASK   0x7f

Definition at line 58 of file pci.c.

#define PCI_HEADER_MULTIFUNC   0x80

Definition at line 59 of file pci.c.

Referenced by pci_scan_bus().

#define PCI_HEADER_NORMAL   0

Definition at line 54 of file pci.c.

#define PCI_HEADER_SZ   256

Definition at line 25 of file pci.c.

#define PCI_MAX_DEV_PER_BUS   32

Definition at line 22 of file pci.c.

Referenced by pci_scan_bus().

#define PCI_MAX_FUNC_PER_DEV   8

Definition at line 23 of file pci.c.

#define PCI_REG_ADDR   0xcf8

Definition at line 18 of file pci.c.

Referenced by pci_read_config(), and pci_write_config().

#define PCI_REG_DATA   0xcfc

Definition at line 19 of file pci.c.

Referenced by pci_read_config(), and pci_write_config().

#define PCI_STATUS_66MHZ   0x20

Definition at line 40 of file pci.c.

#define PCI_STATUS_CAPLIST   0x10

Definition at line 39 of file pci.c.

#define PCI_STATUS_DEVSEL   0x600

Definition at line 44 of file pci.c.

#define PCI_STATUS_DEVSEL_FAST   0

Definition at line 45 of file pci.c.

#define PCI_STATUS_DEVSEL_MED   0x200

Definition at line 46 of file pci.c.

#define PCI_STATUS_DEVSEL_SLOW   0x400

Definition at line 47 of file pci.c.

#define PCI_STATUS_FASTBACK   0x80

Definition at line 42 of file pci.c.

#define PCI_STATUS_PARITY   0x100

Definition at line 43 of file pci.c.

#define PCI_STATUS_PARITY2   0x8000

Definition at line 52 of file pci.c.

#define PCI_STATUS_REC_ABORT   0x1000

Definition at line 49 of file pci.c.

#define PCI_STATUS_REC_ABORT_M   0x2000

Definition at line 50 of file pci.c.

#define PCI_STATUS_SERR   0x4000

Definition at line 51 of file pci.c.

#define PCI_STATUS_SIG_ABORT   0x0800

Definition at line 48 of file pci.c.

#define PCI_STATUS_UDF   0x40

Definition at line 41 of file pci.c.

#define PCI_TRANSLATION_ENABLE   1

Definition at line 1 of file pci.c.

#define PCI_VENDOR_INVALID   0xffff

Definition at line 63 of file pci.c.

Referenced by pci_probe(), and pci_scan_bus().


Enumeration Type Documentation

Enumerator:
PCI_IO_MEM 
PCI_IO_PORT 

Definition at line 126 of file pci.c.


Function Documentation

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]

struct pci_dev* pci_get_device ( int  vendor,
int  device,
int  func,
int  n 
) [read]

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]

struct pci_io* pci_io_enum ( struct pci_dev pio,
struct pci_io last 
) [read]

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().

size_t pci_io_size ( struct pci_io pio  ) 

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]

static void pci_power_on ( struct pci_dev *pd  UNUSED  )  [static]

Definition at line 636 of file pci.c.

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]

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]

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]

uint16_t pci_read_config16 ( struct pci_dev pd,
int  off 
)

Definition at line 767 of file pci.c.

References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().

uint32_t pci_read_config32 ( struct pci_dev pd,
int  off 
)

Definition at line 773 of file pci.c.

References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().

uint8_t pci_read_config8 ( struct pci_dev pd,
int  off 
)

Definition at line 761 of file pci.c.

References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_read_config().

void pci_read_in ( struct pci_io *pio  UNUSED,
int off  UNUSED,
size_t size  UNUSED,
void *buf  UNUSED 
)

Definition at line 411 of file pci.c.

References PANIC.

uint16_t pci_reg_read16 ( struct pci_io pio,
int  reg 
)

uint32_t pci_reg_read32 ( struct pci_io pio,
int  reg 
)

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().

uint8_t pci_reg_read8 ( struct pci_io pio,
int  reg 
)

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().

void pci_reg_write16 ( struct pci_io pio,
int  reg,
uint16_t  data 
)

void pci_reg_write32 ( struct pci_io pio,
int  reg,
uint32_t  data 
)

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().

void pci_reg_write8 ( struct pci_io pio,
int  reg,
uint8_t  data 
)

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 
)

static int pci_scan_bus ( int  bus  )  [static]

static void pci_setup_io ( struct pci_dev pd  )  [static]

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  ) 

static void pci_write_config ( int  bus,
int  dev,
int  func,
int  reg,
int  size,
uint32_t  data 
) [static]

void pci_write_config16 ( struct pci_dev pd,
int  off,
uint16_t  data 
)

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().

void pci_write_config32 ( struct pci_dev pd,
int  off,
uint32_t  data 
)

Definition at line 749 of file pci.c.

References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_write_config().

void pci_write_config8 ( struct pci_dev pd,
int  off,
uint8_t  data 
)

Definition at line 755 of file pci.c.

References pci_dev::bus, pci_dev::dev, pci_dev::func, and pci_write_config().

void pci_write_out ( struct pci_io *pio  UNUSED,
int off  UNUSED,
size_t size  UNUSED,
const void *buf  UNUSED 
)

Definition at line 418 of file pci.c.

References PANIC.


Variable Documentation

struct list devices [static]

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]

Definition at line 164 of file pci.c.

Referenced by pci_alloc_mem(), and pci_init().


Generated on Mon Jan 10 16:43:58 2011 for Pintos by  doxygen 1.5.6