HelenOS sources
This source file includes following definitions.
- disable_extended_caps
- disable_legacy
#include <errno.h>
#include <str_error.h>
#include <assert.h>
#include <ddf/driver.h>
#include <ddi.h>
#include <usb/debug.h>
#include <device/hw_res_parsed.h>
#include <pci_dev_iface.h>
#include "hc.h"
#include "res.h"
#include "ehci_regs.h"
#define USBLEGSUP_OFFSET 0
#define USBLEGSUP_BIOS_CONTROL (1 << 16)
#define USBLEGSUP_OS_CONTROL (1 << 24)
#define USBLEGCTLSTS_OFFSET 4
#define DEFAULT_WAIT 1000
#define WAIT_STEP 10
static errno_t disable_extended_caps(async_sess_t *parent_sess, unsigned eecp)
{
if (eecp == 0)
return EOK;
uint32_t usblegsup;
errno_t ret = pci_config_space_read_32(parent_sess,
eecp + USBLEGSUP_OFFSET, &usblegsup);
if (ret != EOK) {
usb_log_error("Failed to read USBLEGSUP: %s.", str_error(ret));
return ret;
}
usb_log_debug2("USBLEGSUP: %" PRIx32 ".", usblegsup);
usb_log_debug("Requesting OS control.");
ret = pci_config_space_write_8(parent_sess,
eecp + USBLEGSUP_OFFSET + 3, 1);
if (ret != EOK) {
usb_log_error("Failed to request OS EHCI control: %s.",
str_error(ret));
return ret;
}
size_t wait = 0;
ret = pci_config_space_read_32(
parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup);
while ((ret == EOK) && (wait < DEFAULT_WAIT) &&
(usblegsup & USBLEGSUP_BIOS_CONTROL)) {
fibril_usleep(WAIT_STEP);
ret = pci_config_space_read_32(parent_sess,
eecp + USBLEGSUP_OFFSET, &usblegsup);
wait += WAIT_STEP;
}
if ((usblegsup & USBLEGSUP_BIOS_CONTROL) == 0) {
usb_log_info("BIOS released control after %zu usec.", wait);
return EOK;
}
usb_log_warning("BIOS failed to release control after "
"%zu usecs, force it.", wait);
ret = pci_config_space_write_32(parent_sess,
eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
if (ret != EOK) {
usb_log_error("Failed to force OS control: %s.",
str_error(ret));
return ret;
}
if ((usblegsup & 0xff) == 1) {
uint32_t usblegctlsts;
ret = pci_config_space_read_32(parent_sess,
eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
if (ret != EOK) {
usb_log_error("Failed to get USBLEGCTLSTS: %s.",
str_error(ret));
return ret;
}
usb_log_debug2("USBLEGCTLSTS: %" PRIx32 ".", usblegctlsts);
ret = pci_config_space_write_32(parent_sess,
eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
if (ret != EOK) {
usb_log_error("Failed to zero USBLEGCTLSTS: %s",
str_error(ret));
return ret;
}
udelay(10);
ret = pci_config_space_read_32(parent_sess,
eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
if (ret != EOK) {
usb_log_error("Failed to get USBLEGCTLSTS 2: %s.",
str_error(ret));
return ret;
}
usb_log_debug2("Zeroed USBLEGCTLSTS: %" PRIx32 ".",
usblegctlsts);
}
ret = pci_config_space_read_32(parent_sess,
eecp + USBLEGSUP_OFFSET, &usblegsup);
if (ret != EOK) {
usb_log_error("Failed to read USBLEGSUP: %s.",
str_error(ret));
return ret;
}
usb_log_debug2("USBLEGSUP: %" PRIx32 ".", usblegsup);
return ret;
}
errno_t disable_legacy(hc_device_t *hcd)
{
hc_t *hc = hcd_to_hc(hcd);
async_sess_t *parent_sess = ddf_dev_parent_sess_get(hcd->ddf_dev);
if (parent_sess == NULL)
return ENOMEM;
usb_log_debug("Disabling EHCI legacy support.");
const uint32_t hcc_params = EHCI_RD(hc->caps->hccparams);
usb_log_debug2("Value of hcc params register: %x.", hcc_params);
const uint32_t eecp =
(hcc_params >> EHCI_CAPS_HCC_EECP_SHIFT) & EHCI_CAPS_HCC_EECP_MASK;
usb_log_debug2("Value of EECP: %x.", eecp);
int ret = disable_extended_caps(parent_sess, eecp);
if (ret != EOK) {
usb_log_error("Failed to disable extended capabilities: %s.",
str_error(ret));
goto clean;
}
clean:
async_hangup(parent_sess);
return ret;
}
HelenOS homepage, sources at GitHub