hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/usb/core/hcd-pci.c
....@@ -159,6 +159,7 @@
159159 * usb_hcd_pci_probe - initialize PCI-based HCDs
160160 * @dev: USB Host Controller being probed
161161 * @id: pci hotplug id connecting controller to HCD framework
162
+ * @driver: USB HC driver handle
162163 * Context: !in_interrupt()
163164 *
164165 * Allocates basic PCI resources for this USB host controller, and
....@@ -169,9 +170,9 @@
169170 *
170171 * Return: 0 if successful.
171172 */
172
-int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
173
+int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id,
174
+ const struct hc_driver *driver)
173175 {
174
- struct hc_driver *driver;
175176 struct usb_hcd *hcd;
176177 int retval;
177178 int hcd_irq = 0;
....@@ -181,7 +182,7 @@
181182
182183 if (!id)
183184 return -EINVAL;
184
- driver = (struct hc_driver *)id->driver_data;
185
+
185186 if (!driver)
186187 return -EINVAL;
187188
....@@ -193,20 +194,21 @@
193194 * make sure irq setup is not touched for xhci in generic hcd code
194195 */
195196 if ((driver->flags & HCD_MASK) < HCD_USB3) {
196
- if (!dev->irq) {
197
+ retval = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_LEGACY | PCI_IRQ_MSI);
198
+ if (retval < 0) {
197199 dev_err(&dev->dev,
198200 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
199201 pci_name(dev));
200202 retval = -ENODEV;
201203 goto disable_pci;
202204 }
203
- hcd_irq = dev->irq;
205
+ hcd_irq = pci_irq_vector(dev, 0);
204206 }
205207
206208 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
207209 if (!hcd) {
208210 retval = -ENOMEM;
209
- goto disable_pci;
211
+ goto free_irq_vectors;
210212 }
211213
212214 hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) &&
....@@ -222,7 +224,7 @@
222224 retval = -EBUSY;
223225 goto put_hcd;
224226 }
225
- hcd->regs = devm_ioremap_nocache(&dev->dev, hcd->rsrc_start,
227
+ hcd->regs = devm_ioremap(&dev->dev, hcd->rsrc_start,
226228 hcd->rsrc_len);
227229 if (hcd->regs == NULL) {
228230 dev_dbg(&dev->dev, "error mapping memory\n");
....@@ -234,7 +236,7 @@
234236 /* UHCI */
235237 int region;
236238
237
- for (region = 0; region < PCI_ROM_RESOURCE; region++) {
239
+ for (region = 0; region < PCI_STD_NUM_BARS; region++) {
238240 if (!(pci_resource_flags(dev, region) &
239241 IORESOURCE_IO))
240242 continue;
....@@ -285,6 +287,9 @@
285287
286288 put_hcd:
287289 usb_put_hcd(hcd);
290
+free_irq_vectors:
291
+ if ((driver->flags & HCD_MASK) < HCD_USB3)
292
+ pci_free_irq_vectors(dev);
288293 disable_pci:
289294 pci_disable_device(dev);
290295 dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval);
....@@ -310,10 +315,13 @@
310315 void usb_hcd_pci_remove(struct pci_dev *dev)
311316 {
312317 struct usb_hcd *hcd;
318
+ int hcd_driver_flags;
313319
314320 hcd = pci_get_drvdata(dev);
315321 if (!hcd)
316322 return;
323
+
324
+ hcd_driver_flags = hcd->driver->flags;
317325
318326 if (pci_dev_run_wake(dev))
319327 pm_runtime_get_noresume(&dev->dev);
....@@ -342,6 +350,8 @@
342350 up_read(&companions_rwsem);
343351 }
344352 usb_put_hcd(hcd);
353
+ if ((hcd_driver_flags & HCD_MASK) < HCD_USB3)
354
+ pci_free_irq_vectors(dev);
345355 pci_disable_device(dev);
346356 }
347357 EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
....@@ -393,8 +403,7 @@
393403
394404 static int check_root_hub_suspended(struct device *dev)
395405 {
396
- struct pci_dev *pci_dev = to_pci_dev(dev);
397
- struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
406
+ struct usb_hcd *hcd = dev_get_drvdata(dev);
398407
399408 if (HCD_RH_RUNNING(hcd)) {
400409 dev_warn(dev, "Root hub is not suspended\n");
....@@ -454,7 +463,7 @@
454463 * synchronized here.
455464 */
456465 if (!hcd->msix_enabled)
457
- synchronize_irq(pci_dev->irq);
466
+ synchronize_irq(pci_irq_vector(pci_dev, 0));
458467
459468 /* Downstream ports from this root hub should already be quiesced, so
460469 * there will be no DMA activity. Now we can shut down the upstream
....@@ -605,10 +614,10 @@
605614 .suspend_noirq = hcd_pci_suspend_noirq,
606615 .resume_noirq = hcd_pci_resume_noirq,
607616 .resume = hcd_pci_resume,
608
- .freeze = check_root_hub_suspended,
617
+ .freeze = hcd_pci_suspend,
609618 .freeze_noirq = check_root_hub_suspended,
610619 .thaw_noirq = NULL,
611
- .thaw = NULL,
620
+ .thaw = hcd_pci_resume,
612621 .poweroff = hcd_pci_suspend,
613622 .poweroff_noirq = hcd_pci_suspend_noirq,
614623 .restore_noirq = hcd_pci_resume_noirq,