11 #include <soc/pci_devs.h>
16 #define MIN_SHARED_IRQ 16
17 #define MAX_SHARED_IRQ 23
18 #define TOTAL_SHARED_IRQ (MAX_SHARED_IRQ - MIN_SHARED_IRQ + 1)
21 #define IDX2PIN(i) (enum pci_pin)((i) + PCI_INT_A)
22 #define PIN2IDX(p) (size_t)((p) - PCI_INT_A)
77 for (
size_t pin_idx = 0; pin_idx <
PCI_INT_MAX; pin_idx++) {
78 if (
pin_info[pin_idx].pin_state == FREE_PIN)
87 unsigned int least_shared = 255;
90 for (
size_t pin_idx = 0; pin_idx <
PCI_INT_MAX; pin_idx++) {
91 if (
pin_info[pin_idx].pin_state == SHARED_IRQ_PIN &&
92 pin_info[pin_idx].usage_count < least_shared) {
94 least_index = pin_idx;
106 unsigned int least_shared = 255;
107 int least_index = -1;
116 if (least_index >= 0)
145 if (pin < PCI_INT_A || pin >
PCI_INT_D) {
150 const size_t pin_idx =
PIN2IDX(pin);
153 fn_pin_map[fn] = pin;
161 for (
size_t i = 0; i <
MAX_FNS; i++) {
176 for (
size_t i = 0; i <
MAX_FNS; i++) {
183 const enum pci_pin pin = fn_pin_map[i];
200 for (
size_t i = 0; i <
MAX_FNS; i++) {
217 const size_t pin_idx =
PIN2IDX(pin);
227 for (
size_t i = 0; i <
MAX_FNS; i++) {
252 for (
size_t pin_idx = 0; pin_idx <
PCI_INT_MAX; pin_idx++) {
253 if (
pin_info[pin_idx].pin_state != SHARED_IRQ_PIN ||
pin_info[pin_idx].irq != 0)
288 for (
size_t fn = 0; fn <
MAX_FNS; fn++) {
292 const size_t pin_idx =
PIN2IDX(fn_pin_map[fn]);
330 for (
size_t i = 0; i < num_slots; i++) {
368 const uint8_t *legacy_pirq_routing;
370 size_t map_count = 0;
381 for (i = 0; i <
PIRQ_COUNT && i < pirq_routes; i++)
382 pirq_map.
gsi[i] = legacy_pirq_routing[i];
386 const unsigned int slot =
PCI_SLOT(entry->devfn);
393 pin_irq_map[map_count].
slot = slot;
394 pin_irq_map[map_count].
pin = entry->pin;
395 pin_irq_map[map_count].
apic_gsi = entry->irq;
bool is_slot_pin_assigned(const struct slot_pin_irq_map *pin_irq_map, unsigned int map_count, unsigned int slot, enum pci_pin pin)
void intel_write_pci0_PRT(const struct slot_pin_irq_map *pin_irq_map, unsigned int map_count, const struct pic_pirq_map *pirq_map)
static size_t pirq_idx(enum pirq pirq)
static bool assign_fixed_pirqs(const struct slot_irq_constraints *constraints, struct pin_info *pin_info, enum pci_pin fn_pin_map[MAX_FNS])
static bool assign_direct_irqs(const struct slot_irq_constraints *constraints, struct pin_info *pin_info, enum pci_pin fn_pin_map[MAX_FNS])
bool generate_pin_irq_map(void)
int get_pci_devfn_irq(unsigned int devfn)
static bool assign_slot(struct pci_irq_entry **head, const struct slot_irq_constraints *constraints)
bool irq_program_non_pch(void)
static enum pirq irq_to_pirq(unsigned int irq)
static int pirq_to_irq(enum pirq pirq)
static bool assign_pirq(struct pin_info pin_info[PCI_INT_MAX], enum pci_pin pin, enum pirq pirq)
static unsigned int irq_share_count[TOTAL_SHARED_IRQ]
static void add_slot_entries(struct pci_irq_entry **head, unsigned int slot, struct pin_info pin_info[PCI_INT_MAX], const enum pci_pin fn_pin_map[MAX_FNS])
static bool assign_fixed_pins(const struct slot_irq_constraints *constraints, struct pin_info *pin_info, enum pci_pin fn_pin_map[MAX_FNS])
bool assign_pci_irqs(const struct slot_irq_constraints *constraints, size_t num_slots)
static struct pci_irq_entry * cached_entries
const struct pci_irq_entry * get_cached_pci_irqs(void)
static void add_entry(struct pci_irq_entry **head, pci_devfn_t devfn, enum pci_pin pin, unsigned int irq)
static bool assign_shareable_pins(const struct slot_irq_constraints *constraints, struct pin_info *pin_info, enum pci_pin fn_pin_map[MAX_FNS])
static bool assign_pirqs(struct pin_info pin_info[PCI_INT_MAX])
static enum pci_pin find_shareable_pin(const struct pin_info pin_info[PCI_INT_MAX])
static enum pirq find_global_least_used_pirq(void)
static enum pci_pin find_free_pin(const struct pin_info pin_info[PCI_INT_MAX])
static bool assign_pin(enum pci_pin pin, unsigned int fn, enum pin_state state, struct pin_info *pin_info, enum pci_pin fn_pin_map[MAX_FNS])
static int find_free_unique_irq(void)
#define printk(level,...)
void * malloc(size_t size)
void * calloc(size_t nitems, size_t size)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
const uint8_t * lpc_get_pic_pirq_routing(size_t *num)
#define PCI_DEVFN(slot, func)
#define PCI_INTERRUPT_PIN
#define PCI_INTERRUPT_LINE
const char * pin_to_str(int pin)
Take an INT_PIN number (0, 1 - 4) and convert it to a string ("NO PIN", "PIN A" - "PIN D")
static __always_inline void pci_s_write_config8(pci_devfn_t dev, uint16_t reg, uint8_t value)
#define PCI_DEV(SEGBUS, DEV, FN)
bool gpio_routes_ioapic_irq(uint32_t irq)
struct pci_irq_entry * next
unsigned int gsi[PIRQ_COUNT]