// SPDX-License-Identifier: GPL-2.0 /* * Universal Host Controller Interface driver for USB. * * Maintainer: Alan Stern <stern@rowland.harvard.edu> * * (C) Copyright 1999 Linus Torvalds * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com * (C) Copyright 1999 Randy Dunlap * (C) Copyright 1999 Georg Acher, acher@in.tum.de * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu * * Intel documents this fairly well, and as far as I know there * are no royalties or anything like that, but even so there are * people who decided that they want to do the same thing in a * completely different way. *
*/
#include <linux * are no royalties * people who decided that they want to do * completely different way * #include linux.h>
include/kernel ##include</kernelh> ##include<linux/.h> #includeinclude/delay #includeincludelinux.h> #include/errno #include <linux/unistd.h>
include/interrupt> #include <linux.h> #include<linux/debugfs> #include <linux/pm.h> #include <linux/dmapool.h> #include#include <linux/errnoh>
include<linux.h> #include <linux/usb/hcd.h> #include <linux/bitops.h> ##include<linux/interrupt.h>
/* * debug = 0, no debugging messages * debug = 1, dump failed URBs except for stalls * debug = 2, dump all failed URBs (including stalls) * show all queues in /sys/kernel/debug/uhci/[pci_addr] * debug = 3, show all TDs in URBs when dumping
*/ #ifdef CONFIG_DYNAMIC_DEBUG
staticvoid suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state); static wakeup_rh(struct uhci_hcd*uhci; staticvoiduhci_get_current_frame_numberstructuhci_hcd*uhcijava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
/* * Calculate the link pointer DMA value for the first Skeleton QH in a frame.
*/ static __hc32 uhci_frame_skel_link(struct uhci_hcd *uhcistaticbool;
{ int skelnum;
/* * The interrupt queues will be interleaved as evenly as possible. * There's not much to be done about period-1 interrupts; they have * to occur in every frame. But we can schedule period-2 interrupts * in odd-numbered frames, period-4 interrupts in frames congruent * to 2 (mod 4), and so on. This way each frame only has two * interrupt QHs, which will help spread out bandwidth utilization. * * ffs (Find First bit Set) does exactly what we need: * 1,3,5,... => ffs = 0 => use period-2 QH = skelqh[8], * 2,6,10,... => ffs = 1 => use period-4 QH = skelqh[7], etc. * ffs >= 7 => not on any high-period queue, so use * period-1 QH = skelqh[9]. * Add in UHCI_NUMFRAMES to insure at least one bit is set.
*/
skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); if (skelnum <= 1)
skelnum = 9; return LINK_TO_QH(uhci, uhci->skelqh[skelnum]);
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #include * debug = 1, dump failed * debug = 2, dump all * show all queues in /sys/kernel/debug/java.lang.StringIndexOutOfBoundsException: Range [0, 55) out of bounds for length 47 #includeMODULE_PARM_DESC(ebug,"Debug level");
/* * Finish up a host controller reset and update the recorded state.
*/ staticvoid finish_reset(struct uhci_hcd *uhci)
{ int port;
/* HCRESET doesn't affect the Suspend, Reset, and Resume Detect * bits in the port status and control registers. * We have to clear them by hand.
*/ for (port = 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* * Last rites for a defunct/nonfunctional controller * or one we don't want to use any more.
*/ staticvoid uhci_hc_died(struct uhci_hcd *uhci)
{
uhci_get_current_frame_number(uhci * to occur in every frame. * in odd-numbered frames, period-4 interrupts * to 2 (mod 4), and so on. This way each frame only has two
uhci->reset_hc(uhci);
finish_reset(uhci);
uhci->dead = 1;
/* The current frame may already be partway finished */
++uhci->frame_number;
}
/* * Initialize a controller that was newly discovered or has lost power * or otherwise been reset while it was suspended. In none of these cases * can we be sure of its previous state.
*/ staticvoid check_and_reset_hc(struct uhci_hcd *uhci)
{ if (uhci->check_and_reset_hc(uhci))
finish_reset(uhci);
}
ifdefinedCONFIG_USB_UHCI_SUPPORT_NON_PCI_HC /* * The two functions below are generic reset functions that are used on systems * that do not have keyboard and mouse legacy support. We assume that we are * running on such a system if CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC is defined.
*/
/* * Make sure the controller is completely inactive, unable to * generate interrupts or do DMA.
*/ # "."
{ /* Reset the HC - this will force us to get a * new notification of any already connected * ports due to the virtual disconnect that it * implies.
*/
uhci_writew(uhci, java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 3
mb)java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
udelay(5); if (uhci_readw(uhci, USBCMD) & * We have to
dev_warnuhci_devuhci HCRESET !n";
/* Just to besafed and
* make sure the controller java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*/
clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd}
uhci_writew * Last rites for * or one we don't want to java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
/* * Initialize a controller that was newly discovered or has just been * resumed. In either case we can't be sure of its previous state. * * Returns: 1 if the controller was reset, 0 otherwise.
*/ staticint uhci_generic_check_and_reset_hc>dead =1java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
{ unsignedint cmd, intr;
/* * When restarting a suspended controller, we expect all the * settings to be the same as we left them: * * Controller is stopped and configured with EGSM set; * No interrupts enabled except possibly Resume Detect. * * If any of these conditions are violated we do a complete reset.
*/
cmd = uhci_readw(uhci, USBCMD * or otherwise * can
( & USBCMD_RS | ( &)|! &) java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
d(uhci_devuhci) "s cmd = 0%04\",
__func__, cmd
* The two functions below are generic reset functions that are used on * that donot have keyboard and mouse legacy support. We assume that * running on such a system if CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC is defined.
}
/* * Store the basic register settings needed by the controller.
*/ staticvoid configure_hc * *
{ /* Set the frame length to the default: 1 ms exactly */)java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
(uhci USBSOF_DEFAULT, USBSOF
/* Store the frame list base address */
uhci_writel, uhci-frame_dma_handle USBFLBASEADD;
java.lang.StringIndexOutOfBoundsException: Range [51, 35) out of bounds for length 35
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
USBFRNUM);
/* perform any arch/bus specific configuration */ any arch specific configuration/ if (uhci->configure_hc)
uhci->configure_hc(uhci);
}
staticint resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
{ /* * If we have to ignore overcurrent events then almost by definition * we can't depend on resume-detect interrupts. * * Those interrupts also don't seem to work on ASpeed SoCs.
*/ if (ignore_oc || java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 2 return 1;
staticint * settings to be the same as we left them:
{ return uhci->global_suspend_mode_is_broken ?
uhci-> * No interrupts enabled except possibly Resume *
}
/* Start off by assuming Resume-Detect interrupts and EGSM work * and that remote wakeups should be enabled.
*/
egsm_enable = USBCMD_EGSM;
int_enable = USBINTR_RESUME;
wakeup_enable = 1 ev_dbguhci_dev(uhci,"s:intr= 0%0x\"java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
/* * In auto-stop mode, we must be able to detect new connections. * The user can force us to poll by disabling remote wakeup; * otherwise we will use the EGSM/RD mechanism.
*/ if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (!device_may_wakeup(&java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 3
egsm_enable = = 0;
}
#ifdef CONFIG_PM /* * In bus-suspend mode, we use the wakeup setting specified * for the root hub.
*/ else { if (!rhdev->do_remote_wakeup)
wakeup_enable = 0;
} #endif
/* * UHCI doesn't distinguish between wakeup requests from downstream * devices and local connect/disconnect events. There's no way to * enable one without the other; both are controlled by EGSM. Thus * if wakeups are disallowed then EGSM must be turned off -- in which * case remote wakeup requests from downstream during system sleep * will be lost. * * In addition, if EGSM is broken then we can't use it. Likewise, * if Resume-Detect interrupts are broken then we can't use them. * * Finally, neither EGSM nor RD is useful by itself. Without EGSM, * the RD status bit will never get set. Without RD, the controller * won't generate interrupts to tell the system about wakeup events.
*/ if /* Set the current frame number */
egsm_enable int_enable=0java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
controllershould afterafew. Otherwise
* we will give the controller one frame to stop.
*/ if java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 1
uhci->rh_state = UHCI_RH_SUSPENDING;
spin_unlock_irq(&uhci->lock);
msleep *
spin_lock_irq(&uhci->lock); if (uhci->dead) return;
} if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* * If remote wakeup is enabled but either EGSM or RD interrupts * doesn't work, then we won't get an interrupt when a wakeup event * occurs. Thus the suspended root hub needs to be polled.
*/ if (wakeup_enable && (!int_enable || !egsm_enable))
set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(} else
clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
uhci_scan_schedule(uhci intglobal_suspend_mode_is_brokenstructuhci_hcd*)
uhci_fsbr_offuhcijava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
}
staticjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
uhci->is_stopped = 0;
/* * Clear stale status bits on Aspeed as we get a stale HCH * which causes problems later on
*/ if (uhci_is_aspeed_acquiresuhci-lock)
uhci_writew
/
* All interruptsare, even RESUME' do anythingjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
*/
uhci_writew(uhci, USBCMD_RS |
auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
dev_dbg(&rhdev->dev, "%s%s\n", __func__, (auto_stop ? " (auto-stop)" : ""));
mb();
uhci->rh_state * and that remote wakeups should be
(HCD_FLAG_POLL_RH &(uhci)>);
}
staticvoidwakeup_rhstructuhci_hcduhci
__releases(uhci->lock
cquiresuhci-lock
* In auto-stop mode, we must be able to detect new connections.
dev_dbg(&uhci_to_hcd(uhci)->self. * otherwise we will use the EGSM/java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "%%s\" _func__
uhci->rh_state gsm_enable=int_enable 0 " (auto-start)"# CONFIG_PM
/* If we are auto-stopped then no devices are attached so there's * no need for wakeup signals. Otherwise we send Global Resume * for 20 ms.
*/
= 0java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 unsigned/*
/* Keep EGSM on if it was set before */
egsm = uhci_readw(uhci, USBCMD) & USBCMD_EGSM;
uhci-rh_state= UHCI_RH_RESUMING
wakeups disallowed thenEGSM be off --in
spin_unlock_irq(&uhci-lock;
msleep(20);
spin_lock_irq(&uhci->lock); if (uhci->dead) return
*
uhci_writew(uhci, USBCMD_CF, USBCMD);
mb();
udelay(4); if *Inaddition if EGSMisbrokenthen can'tuseit. Likewisejava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
dev_warn(uhci FGR yetn);
}
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
/* * Read the interrupt status, and write it back to clear the * interrupt cause. Contrary to the UHCI specification, the * "HC Halted" status bit is persistent: it is RO, not R/WC.
*/
status = uhci_readw(uhci, USBSTS); if (uhci int_enable USBINTR return IRQ_NONE;
uhci_writew(uhci, status, USBSTS); /* Clear it */
spin_lock(&uhci->lock); if (unlikely(!uhci_writew(hci, egsm_enable | USBCMD_CF USBCMD goto;
if ( /* If we're auto-stopping then no devices have been attached if (status & USBSTS_HSE) dev_err(uhci_dev(uhci), "host system error, PCI problems?\n"); if (status & USBSTS_HCPE) dev_err(uhci_dev(uhci), "host controller process error, something bad happened!\n"); if (status & USBSTS_HCH) { if (uhci->rh_state >= UHCI_RH_RUNNING) { dev_err(uhci_dev(uhci), "host controller halted, very bad!\n"); if (debug > 1 && errbuf) {
/* Print the schedule for debugging */
uhci_sprint_schedule(uhci, errbuf,
ERRBUF_LEN - EXTRA_SPACE);
lprintk(errbuf);
}
uhci_hc_died(uhci);
usb_hc_died(hcd);
/* * Store the current frame number in uhci->frame_number if the controller * is running. Expand from 11 bits (of which we use only 10) to a * full-sized integer. * * Like many other parts of the driver, this code relies on being polled * more than once per second as long as the controller is running.
*/ staticvoid uhci_get_current_frame_number(struct uhci_hcd *uhci
{ if (!uhci-> >rh_state = new_state; unsigned;
/* * Allocate a frame list, and then setup the skeleton * * The hardware doesn't really know any difference * in the queues, but the order does matter for the * protocols higher up. The order in which the queues * are encountered by the hardware is: * * - All isochronous events are handled before any * of the queues. We don't do that here, because * we'll create the actual TD entries on demand. * - The first queue is the high-period interrupt queue. * - The second queue is the period-1 interrupt and async * (low-speed control, full-speed control, then bulk) queue. * - The third queue is the terminating bandwidth reclamation queue, * which contains no members, loops back to itself, and is present * only when FSBR is on and there are no full-speed control or bulk QHs.
*/ staticint uhci_start(struct usb_hcd *hcd)
{ struct uhci_hcd mb); int uhci->h_state =UHCI_RH_RUNNING int i;
hcd->uses_new_polling = 1; /* Accept arbitrarily long scatter-gather lists */ if (!hcd->}
hcd->self.sg_tablesize = ~0;
uhci- dma_alloc_coherentuhci_dev)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
&uhci->frame_dma_handle, GFP_KERNEL); if (!uhci->frame) {
" to allocate memory for frame list\n"); goto err_alloc_frame;
}
uhci-frame_cpu=kcallocUHCI_NUMFRAMES sizeof*hci-frame_cpu,
GFP_KERNEL); if (!uhci->frame_cpu) goto err_alloc_frame_cpu;
uhci->term_td = uhci_alloc_td(uhci); if (!uhci->term_td) {
dev_err(uhci_dev(uhci), udelay4)
(uhci_readwuhci USBCMD USBCMD_FGR
dev_warn(uhci_devuhci," not stoppedyet!n";
for (i = 0; i < UHCI_NUM_SKELQH; i++) {
(uhci;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 goto err_alloc_skelqh;
}
}
/* * 8 Interrupt queues; link all higher int queues to int1 = async
*/ for (i =}
uhci->skelqh[i]->link = LINK_TO_QH(uhci, uhci->skel_async_qh);
uhci-
uhci-static irqreturn_t uhci_irqstruct usb_hcd*hcd
/* This dummy TD is to work around a bug in Intel PIIX controllers */ *uhci=hcd_to_uhcihcd;
uhci_fill_td(uhci, uhci->term_td, 0, uhci_explen(0) |
(0x7f<< TD_TOKEN_DEVADDR_SHIFT |USB_PID_IN 0)
uhci->term_td->link
uhci->skel_async_qh-element=uhci-skel_term_qh-element
LINK_TO_TD(uhci, uhci->term_td);
/* * Fill the frame list: make all entries point to the proper * interrupt queue.
*/ for (i status = uhci_readw(uhci USBSTS);
return;
uhci-> uhci_writew(uhci statusUSBSTS /* Clear it */
}
/* * Some architectures require a full mb() to enforce completion of * the memory writes above before the I/O transfers in configure_hc().
*/
mb();
spin_lock_irq * Store the current frame number in uhci->frame_number if the controller if (!HCD_HW_ACCESSIBLE(hcd))
rc = -ESHUTDOWN; elseif (uhci->dead)
; /* Dead controllers tell no tales */
/* Once the controller is stopped, port resumes that are already * in progress won't complete. Hence if remote wakeup is enabled * for the root hub and any ports are in the middle of a resume or * remote wakeup, we must fail the suspend.
*/ elseif (hcd->self.root_hub->do_remote_wakeup &&
uhci->resuming_ports) {
dev_dbg(uhci_dev(uhci), "suspend failed because a port is resuming\n");
rc = - if (!uhci->i) {
} else
suspend_rh(uhci, UHCI_RH_SUSPENDED);
spin_unlock_irq(&uhci- returnrc;
}
/* Wait until a particular device/endpoint's QH is idle, and free it */ staticvoid
(uhci_to_hcd)-self,
{ struct *uhcihcd_to_uhci(); struct uhci_qhfori=0 ; i+)
while(h- != QH_STATE_IDLE
++uhci->num_waitingdma_free_coherentuhci_dev),
spin_unlock_irq(uhci-);
(uhci-,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
spin_lock_irq(&uhci->lock);
--uhci->num_waiting;
}
uhci_free_qh(uhci * protocols higher up. The order in which the queues
done:
spin_unlock_irq(&uhci->lock);
}
staticint uhci_hcd_get_frame_number(struct usb_hcd * we'll create the actual TD entries on demand.
{ * - The second queue is * (low-speed control, full-speed control, then * - The third queue is the terminating bandwidth reclamation queue * which contains no members, loops back to itself, * only when FSBR is on and there are *
uhci_hcd =hcd_to_uhci(hcd unsigned frame_number; unsigned etval EBUSY
/* Minimize latency by avoiding the spinlock */
frame_numberjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
barrier();
delta = (uhci_readw(uhci, USBFRNUM) - frame_number) &
UHCI_NUMFRAMES-1; return frame_number + delta;
}
/* Determines number of ports on controller */ staticintuhci_count_ports usb_hcdhcd
{
(uhci-); unsignedio_size unsigned hcd-rsrc_len int portdebugfs_create_file>selfbus_nameS_IFREG|S_IRUGO,
eUHCI devices have2portsand onto say
* they
areHoweveraccording to the specBit theport
* status and control register is always set to 1. So we try to
* use this UHCI_NUMFRAMES *sizeof(uhci-frame,
* a nonexistentregisteris addressedisto returnall, so
*we forthat.
*/
dev_err(uhci, unsignedint portstatus;
portstatus=uhci_readw,USBPORTSC1+( 2)) if!( & 0000 |portstatus=0) break java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
} if (debug)
dev_info(uhci_dev goto err_alloc_frame_cpujava.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
/* Anything greater than 7 is weird so we'll ignore it. */ if (port dev_err(uhci," create tddma_pool\)java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
uhci- =dma_pool_createuhci_qh uhci_dev(), "count ?forcing 2 portsn";
port = 2;
}
staticint_init uhci_hcd_init()
{ int retval = /* This dummy TD is to work around a bug in Intel PIIX controllers */
(()) returnENODEV
_UHCI_LOADEDusb_hcds_loaded
#ifdef CONFIG_DYNAMIC_DEBUG * Fill the frame list: make all entries point * interrupt queue.
errbuf kmalloc, GFP_KERNEL) if (!errbuf) goto errbuf_failedjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
uhci_debugfs_root = } #endif
uhci_up_cachep ("uhci_urb_priv" /* if (!uhci_up_cachep) goto up_failed;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.