coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
cardbus_device.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ops.h>
7 #include <device/cardbus.h>
8 
9 /*
10  * I don't think this code is quite correct but it is close.
11  * Anyone with a cardbus bridge and a little time should be able
12  * to make it usable quickly. -- Eric Biederman 24 March 2005
13  */
14 
15 /*
16  * IO should be max 256 bytes. However, since we may have a P2P bridge below
17  * a cardbus bridge, we need 4K.
18  */
19 #define CARDBUS_IO_SIZE 4096
20 #define CARDBUS_MEM_SIZE (32 * 1024 * 1024)
21 
22 static void cardbus_record_bridge_resource(struct device *dev, resource_t moving,
23  resource_t min_size, unsigned int index, unsigned long type)
24 {
25  struct resource *resource;
26  unsigned long gran;
27  resource_t step;
28 
29  /* Initialize the constraints on the current bus. */
30  resource = NULL;
31  if (!moving)
32  return;
33 
34  resource = new_resource(dev, index);
35  resource->size = 0;
36  gran = 0;
37  step = 1;
38  while ((moving & step) == 0) {
39  gran += 1;
40  step <<= 1;
41  }
42  resource->gran = gran;
43  resource->align = gran;
44  resource->limit = moving | (step - 1);
45  resource->flags = type;
46 
47  /* Don't let the minimum size exceed what we can put in the resource. */
48  if ((min_size - 1) > resource->limit)
49  min_size = resource->limit + 1;
50 
51  resource->size = min_size;
52 }
53 
54 void cardbus_read_resources(struct device *dev)
55 {
56  resource_t moving_base, moving_limit, moving;
57  unsigned long type;
58  u16 ctl;
59 
60  /* See if needs a card control registers base address. */
61 
63 
64  compact_resources(dev);
65 
66  /* See which bridge I/O resources are implemented. */
67  moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0);
68  moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_0);
69  moving = moving_base & moving_limit;
70 
71  /* Initialize the I/O space constraints on the current bus. */
74 
75  /* See which bridge I/O resources are implemented. */
76  moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1);
77  moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_1);
78  moving = moving_base & moving_limit;
79 
80  /* Initialize the I/O space constraints on the current bus. */
83 
84  /* If I can, enable prefetch for mem0. */
91 
92  /* See which bridge memory resources are implemented. */
93  moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0);
94  moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_0);
95  moving = moving_base & moving_limit;
96 
97  /* Initialize the memory space constraints on the current bus. */
103 
104  /* See which bridge memory resources are implemented. */
105  moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1);
106  moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_1);
107  moving = moving_base & moving_limit;
108 
109  /* Initialize the memory space constraints on the current bus. */
112 
113  compact_resources(dev);
114 }
115 
117 {
118  u16 ctrl;
119 
121  ctrl |= (dev->link_list->bridge_ctrl & (
125  /* Error check */
127  printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
129 
131 }
132 
135  .set_resources = pci_dev_set_resources,
136  .enable_resources = cardbus_enable_resources,
137  .scan_bus = pci_scan_bridge,
138  .reset_bus = pci_bus_reset,
139 };
struct device_operations default_cardbus_ops_bus
static void cardbus_record_bridge_resource(struct device *dev, resource_t moving, resource_t min_size, unsigned int index, unsigned long type)
void cardbus_enable_resources(struct device *dev)
#define CARDBUS_MEM_SIZE
#define CARDBUS_IO_SIZE
void cardbus_read_resources(struct device *dev)
#define printk(level,...)
Definition: stdlib.h:16
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
void compact_resources(struct device *dev)
See if we have unused but allocated resource structures.
Definition: device_util.c:302
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
unsigned int type
Definition: edid.c:57
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define PCI_BRIDGE_CTL_MASTER_ABORT
Definition: pci_def.h:141
#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM1
Definition: pci_def.h:180
#define PCI_CB_BRIDGE_CTL_PARITY
Definition: pci_def.h:170
#define PCI_CB_BRIDGE_CTL_SERR
Definition: pci_def.h:171
#define PCI_CB_MEMORY_LIMIT_1
Definition: pci_def.h:157
#define PCI_CB_MEMORY_BASE_1
Definition: pci_def.h:156
#define PCI_CB_IO_BASE_0
Definition: pci_def.h:158
#define PCI_CB_MEMORY_BASE_0
Definition: pci_def.h:154
#define PCI_CB_BRIDGE_CONTROL
Definition: pci_def.h:168
#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM0
Definition: pci_def.h:179
#define PCI_CB_IO_LIMIT_1
Definition: pci_def.h:164
#define PCI_CB_MEMORY_LIMIT_0
Definition: pci_def.h:155
#define PCI_BRIDGE_CTL_BUS_RESET
Definition: pci_def.h:142
#define PCI_BRIDGE_CTL_VGA
Definition: pci_def.h:139
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_CB_IO_BASE_1
Definition: pci_def.h:162
#define PCI_CB_IO_LIMIT_0
Definition: pci_def.h:160
void pci_bus_reset(struct bus *bus)
Definition: pci_device.c:777
u32 pci_moving_config32(struct device *dev, unsigned int reg)
Definition: pci_device.c:62
void pci_scan_bridge(struct device *dev)
Scan a PCI bridge and the buses behind the bridge.
Definition: pci_device.c:1598
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
struct resource * pci_get_resource(struct device *dev, unsigned long index)
Given a device and register, read the size of the BAR for that register.
Definition: pci_device.c:86
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_IO
Definition: resource.h:9
u64 resource_t
Definition: resource.h:43
#define IORESOURCE_PREFETCH
Definition: resource.h:17
#define NULL
Definition: stddef.h:19
uint16_t u16
Definition: stdint.h:48
unsigned int bridge_ctrl
Definition: device.h:81
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
DEVTREE_CONST struct bus * link_list
Definition: device.h:139
unsigned long flags
Definition: resource.h:49
unsigned char align
Definition: resource.h:51
resource_t limit
Definition: resource.h:47
unsigned char gran
Definition: resource.h:52
unsigned long index
Definition: resource.h:50
resource_t size
Definition: resource.h:46