Contiki 3.x
pci.h
1 /*
2  * Copyright (C) 2015, Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef CPU_X86_DRIVERS_LEGACY_PC_PCI_H_
32 #define CPU_X86_DRIVERS_LEGACY_PC_PCI_H_
33 
34 #include <stdint.h>
35 #include "helpers.h"
36 #include <stdlib.h>
37 #include "prot-domains.h"
38 
39 /** PCI configuration register identifier for Base Address Registers */
40 #define PCI_CONFIG_REG_BAR0 0x10
41 #define PCI_CONFIG_REG_BAR1 0x14
42 
43 /** PCI Interrupt Routing is mapped using Interrupt Queue Agents */
44 typedef enum {
45  IRQAGENT0,
46  IRQAGENT1,
47  IRQAGENT2,
48  IRQAGENT3
49 } IRQAGENT;
50 
51 /** PCI Interupt Pins */
52 typedef enum {
53  INTA,
54  INTB,
55  INTC,
56  INTD
57 } INTR_PIN;
58 
59 /**
60  * PCI based interrupts PIRQ[A:H] are then available for consumption by either
61  * the 8259 PICs or the IO-APIC.
62  */
63 typedef enum {
64  PIRQA,
65  PIRQB,
66  PIRQC,
67  PIRQD,
68  PIRQE,
69  PIRQF,
70  PIRQG,
71  PIRQH,
72 } PIRQ;
73 
74 /** PCI command register bit to enable bus mastering */
75 #define PCI_CMD_2_BUS_MST_EN BIT(2)
76 /** PCI command register bit to enable memory space */
77 #define PCI_CMD_1_MEM_SPACE_EN BIT(1)
78 
79 /**
80  * PCI configuration address
81  *
82  * Refer to Intel Quark SoC X1000 Datasheet, Section 5.5 for more details on
83  * PCI configuration register access.
84  */
85 typedef union pci_config_addr {
86  struct {
87  /** Register/offset number. Least-significant two bits should be zero. */
88  uint32_t reg_off : 8;
89  uint32_t func : 3; /**< Function number */
90  uint32_t dev : 5; /**< Device number */
91  uint32_t bus : 8; /**< Bus number */
92  uint32_t : 7;
93  /** Must be set to perform PCI configuration access. */
94  uint32_t en_mapping : 1;
95  };
96  uint32_t raw;
98 
99 uint32_t pci_config_read(pci_config_addr_t addr);
100 void pci_config_write(pci_config_addr_t addr, uint32_t data);
101 void pci_command_enable(pci_config_addr_t addr, uint32_t flags);
102 
104 
105 void pci_init(pci_driver_t ATTR_KERN_ADDR_SPACE *c_this,
106  pci_config_addr_t pci_addr,
107  size_t mmio_sz,
108  uintptr_t meta,
109  size_t meta_sz);
110 void pci_irq_agent_set_pirq(IRQAGENT agent, INTR_PIN pin, PIRQ pirq);
111 void pci_pirq_set_irq(PIRQ pirq, uint8_t irq, uint8_t route_to_legacy);
112 void pci_root_complex_init(void);
113 void pci_root_complex_lock(void);
114 
115 #define PCI_MMIO_READL(c_this, dest, reg_addr) \
116  MMIO_READL(dest, \
117  *((volatile uint32_t ATTR_MMIO_ADDR_SPACE *) \
118  (((uintptr_t)PROT_DOMAINS_MMIO(c_this)) + (reg_addr))))
119 #define PCI_MMIO_WRITEL(c_this, reg_addr, src) \
120  MMIO_WRITEL(*((volatile uint32_t ATTR_MMIO_ADDR_SPACE *) \
121  (((uintptr_t)PROT_DOMAINS_MMIO(c_this)) + (reg_addr))), \
122  src)
123 
124 #endif /* CPU_X86_DRIVERS_LEGACY_PC_PCI_H_ */
uint32_t func
Function number.
Definition: pci.h:89
static uip_ds6_addr_t * addr
Pointer to a router list entry.
Definition: uip-nd6.c:124
PCI configuration address.
Definition: pci.h:85
uint32_t dev
Device number.
Definition: pci.h:90
uint32_t bus
Bus number.
Definition: pci.h:91
Data associated with each protection domain that is owned by clients of that domain and used to ident...
Definition: prot-domains.h:247
uint32_t en_mapping
Must be set to perform PCI configuration access.
Definition: pci.h:94
uint32_t reg_off
Register/offset number.
Definition: pci.h:88