diff options
Diffstat (limited to 'drivers/pci/hotplug/pciehp_pci.c')
-rw-r--r-- | drivers/pci/hotplug/pciehp_pci.c | 152 |
1 files changed, 148 insertions, 4 deletions
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 4017fb03a0b8..854aaea09e4d 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c | |||
@@ -34,6 +34,144 @@ | |||
34 | #include "../pci.h" | 34 | #include "../pci.h" |
35 | #include "pciehp.h" | 35 | #include "pciehp.h" |
36 | 36 | ||
37 | static void program_hpp_type0(struct pci_dev *dev, struct hpp_type0 *hpp) | ||
38 | { | ||
39 | u16 pci_cmd, pci_bctl; | ||
40 | |||
41 | if (hpp->revision > 1) { | ||
42 | printk(KERN_WARNING "%s: Rev.%d type0 record not supported\n", | ||
43 | __FUNCTION__, hpp->revision); | ||
44 | return; | ||
45 | } | ||
46 | |||
47 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, hpp->cache_line_size); | ||
48 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, hpp->latency_timer); | ||
49 | pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); | ||
50 | if (hpp->enable_serr) | ||
51 | pci_cmd |= PCI_COMMAND_SERR; | ||
52 | else | ||
53 | pci_cmd &= ~PCI_COMMAND_SERR; | ||
54 | if (hpp->enable_perr) | ||
55 | pci_cmd |= PCI_COMMAND_PARITY; | ||
56 | else | ||
57 | pci_cmd &= ~PCI_COMMAND_PARITY; | ||
58 | pci_write_config_word(dev, PCI_COMMAND, pci_cmd); | ||
59 | |||
60 | /* Program bridge control value */ | ||
61 | if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { | ||
62 | pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, | ||
63 | hpp->latency_timer); | ||
64 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl); | ||
65 | if (hpp->enable_serr) | ||
66 | pci_bctl |= PCI_BRIDGE_CTL_SERR; | ||
67 | else | ||
68 | pci_bctl &= ~PCI_BRIDGE_CTL_SERR; | ||
69 | if (hpp->enable_perr) | ||
70 | pci_bctl |= PCI_BRIDGE_CTL_PARITY; | ||
71 | else | ||
72 | pci_bctl &= ~PCI_BRIDGE_CTL_PARITY; | ||
73 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) | ||
78 | { | ||
79 | int pos; | ||
80 | u16 reg16; | ||
81 | u32 reg32; | ||
82 | |||
83 | if (hpp->revision > 1) { | ||
84 | printk(KERN_WARNING "%s: Rev.%d type2 record not supported\n", | ||
85 | __FUNCTION__, hpp->revision); | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | /* Find PCI Express capability */ | ||
90 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); | ||
91 | if (!pos) | ||
92 | return; | ||
93 | |||
94 | /* Initialize Device Control Register */ | ||
95 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, ®16); | ||
96 | reg16 = (reg16 & hpp->pci_exp_devctl_and) | hpp->pci_exp_devctl_or; | ||
97 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, reg16); | ||
98 | |||
99 | /* Initialize Link Control Register */ | ||
100 | if (dev->subordinate) { | ||
101 | pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, ®16); | ||
102 | reg16 = (reg16 & hpp->pci_exp_lnkctl_and) | ||
103 | | hpp->pci_exp_lnkctl_or; | ||
104 | pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, reg16); | ||
105 | } | ||
106 | |||
107 | /* Find Advanced Error Reporting Enhanced Capability */ | ||
108 | pos = 256; | ||
109 | do { | ||
110 | pci_read_config_dword(dev, pos, ®32); | ||
111 | if (PCI_EXT_CAP_ID(reg32) == PCI_EXT_CAP_ID_ERR) | ||
112 | break; | ||
113 | } while ((pos = PCI_EXT_CAP_NEXT(reg32))); | ||
114 | if (!pos) | ||
115 | return; | ||
116 | |||
117 | /* Initialize Uncorrectable Error Mask Register */ | ||
118 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, ®32); | ||
119 | reg32 = (reg32 & hpp->unc_err_mask_and) | hpp->unc_err_mask_or; | ||
120 | pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, reg32); | ||
121 | |||
122 | /* Initialize Uncorrectable Error Severity Register */ | ||
123 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, ®32); | ||
124 | reg32 = (reg32 & hpp->unc_err_sever_and) | hpp->unc_err_sever_or; | ||
125 | pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, reg32); | ||
126 | |||
127 | /* Initialize Correctable Error Mask Register */ | ||
128 | pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, ®32); | ||
129 | reg32 = (reg32 & hpp->cor_err_mask_and) | hpp->cor_err_mask_or; | ||
130 | pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg32); | ||
131 | |||
132 | /* Initialize Advanced Error Capabilities and Control Register */ | ||
133 | pci_read_config_dword(dev, pos + PCI_ERR_CAP, ®32); | ||
134 | reg32 = (reg32 & hpp->adv_err_cap_and) | hpp->adv_err_cap_or; | ||
135 | pci_write_config_dword(dev, pos + PCI_ERR_CAP, reg32); | ||
136 | |||
137 | /* | ||
138 | * FIXME: The following two registers are not supported yet. | ||
139 | * | ||
140 | * o Secondary Uncorrectable Error Severity Register | ||
141 | * o Secondary Uncorrectable Error Mask Register | ||
142 | */ | ||
143 | } | ||
144 | |||
145 | static void program_fw_provided_values(struct pci_dev *dev) | ||
146 | { | ||
147 | struct pci_dev *cdev; | ||
148 | struct hotplug_params hpp; | ||
149 | |||
150 | /* Program hpp values for this device */ | ||
151 | if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL || | ||
152 | (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE && | ||
153 | (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))) | ||
154 | return; | ||
155 | |||
156 | if (pciehp_get_hp_params_from_firmware(dev, &hpp)) { | ||
157 | printk(KERN_WARNING "%s: Could not get hotplug parameters\n", | ||
158 | __FUNCTION__); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | if (hpp.t2) | ||
163 | program_hpp_type2(dev, hpp.t2); | ||
164 | if (hpp.t0) | ||
165 | program_hpp_type0(dev, hpp.t0); | ||
166 | |||
167 | /* Program child devices */ | ||
168 | if (dev->subordinate) { | ||
169 | list_for_each_entry(cdev, &dev->subordinate->devices, | ||
170 | bus_list) | ||
171 | program_fw_provided_values(cdev); | ||
172 | } | ||
173 | } | ||
174 | |||
37 | static int pciehp_add_bridge(struct pci_dev *dev) | 175 | static int pciehp_add_bridge(struct pci_dev *dev) |
38 | { | 176 | { |
39 | struct pci_bus *parent = dev->bus; | 177 | struct pci_bus *parent = dev->bus; |
@@ -66,10 +204,11 @@ int pciehp_configure_device(struct slot *p_slot) | |||
66 | struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate; | 204 | struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate; |
67 | int num, fn; | 205 | int num, fn; |
68 | 206 | ||
69 | dev = pci_find_slot(p_slot->bus, PCI_DEVFN(p_slot->device, 0)); | 207 | dev = pci_get_slot(parent, PCI_DEVFN(p_slot->device, 0)); |
70 | if (dev) { | 208 | if (dev) { |
71 | err("Device %s already exists at %x:%x, cannot hot-add\n", | 209 | err("Device %s already exists at %x:%x, cannot hot-add\n", |
72 | pci_name(dev), p_slot->bus, p_slot->device); | 210 | pci_name(dev), p_slot->bus, p_slot->device); |
211 | pci_dev_put(dev); | ||
73 | return -EINVAL; | 212 | return -EINVAL; |
74 | } | 213 | } |
75 | 214 | ||
@@ -86,14 +225,15 @@ int pciehp_configure_device(struct slot *p_slot) | |||
86 | if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) { | 225 | if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) { |
87 | err("Cannot hot-add display device %s\n", | 226 | err("Cannot hot-add display device %s\n", |
88 | pci_name(dev)); | 227 | pci_name(dev)); |
228 | pci_dev_put(dev); | ||
89 | continue; | 229 | continue; |
90 | } | 230 | } |
91 | if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || | 231 | if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) || |
92 | (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) { | 232 | (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) { |
93 | pciehp_add_bridge(dev); | 233 | pciehp_add_bridge(dev); |
94 | } | 234 | } |
95 | /* TBD: program firmware provided _HPP values */ | 235 | program_fw_provided_values(dev); |
96 | /* program_fw_provided_values(dev); */ | 236 | pci_dev_put(dev); |
97 | } | 237 | } |
98 | 238 | ||
99 | pci_bus_assign_resources(parent); | 239 | pci_bus_assign_resources(parent); |
@@ -106,18 +246,20 @@ int pciehp_unconfigure_device(struct slot *p_slot) | |||
106 | int rc = 0; | 246 | int rc = 0; |
107 | int j; | 247 | int j; |
108 | u8 bctl = 0; | 248 | u8 bctl = 0; |
249 | struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate; | ||
109 | 250 | ||
110 | dbg("%s: bus/dev = %x/%x\n", __FUNCTION__, p_slot->bus, | 251 | dbg("%s: bus/dev = %x/%x\n", __FUNCTION__, p_slot->bus, |
111 | p_slot->device); | 252 | p_slot->device); |
112 | 253 | ||
113 | for (j=0; j<8 ; j++) { | 254 | for (j=0; j<8 ; j++) { |
114 | struct pci_dev* temp = pci_find_slot(p_slot->bus, | 255 | struct pci_dev* temp = pci_get_slot(parent, |
115 | (p_slot->device << 3) | j); | 256 | (p_slot->device << 3) | j); |
116 | if (!temp) | 257 | if (!temp) |
117 | continue; | 258 | continue; |
118 | if ((temp->class >> 16) == PCI_BASE_CLASS_DISPLAY) { | 259 | if ((temp->class >> 16) == PCI_BASE_CLASS_DISPLAY) { |
119 | err("Cannot remove display device %s\n", | 260 | err("Cannot remove display device %s\n", |
120 | pci_name(temp)); | 261 | pci_name(temp)); |
262 | pci_dev_put(temp); | ||
121 | continue; | 263 | continue; |
122 | } | 264 | } |
123 | if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE) { | 265 | if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE) { |
@@ -125,10 +267,12 @@ int pciehp_unconfigure_device(struct slot *p_slot) | |||
125 | if (bctl & PCI_BRIDGE_CTL_VGA) { | 267 | if (bctl & PCI_BRIDGE_CTL_VGA) { |
126 | err("Cannot remove display device %s\n", | 268 | err("Cannot remove display device %s\n", |
127 | pci_name(temp)); | 269 | pci_name(temp)); |
270 | pci_dev_put(temp); | ||
128 | continue; | 271 | continue; |
129 | } | 272 | } |
130 | } | 273 | } |
131 | pci_remove_bus_device(temp); | 274 | pci_remove_bus_device(temp); |
275 | pci_dev_put(temp); | ||
132 | } | 276 | } |
133 | /* | 277 | /* |
134 | * Some PCI Express root ports require fixup after hot-plug operation. | 278 | * Some PCI Express root ports require fixup after hot-plug operation. |