003 File Manager
Current Path:
/usr/src/sys/dev/usb
usr
/
src
/
sys
/
dev
/
usb
/
📁
..
📁
controller
📁
gadget
📁
input
📁
misc
📁
net
📁
quirk
📁
serial
📁
storage
📁
template
📄
ufm_ioctl.h
(1.85 KB)
📄
uftdiio.h
(3.51 KB)
📄
uled_ioctl.h
(1.61 KB)
📄
usb.h
(24.12 KB)
📄
usb_bus.h
(4.41 KB)
📄
usb_busdma.c
(27.5 KB)
📄
usb_busdma.h
(5.26 KB)
📄
usb_cdc.h
(8.17 KB)
📄
usb_controller.h
(6.1 KB)
📄
usb_core.c
(2.53 KB)
📄
usb_core.h
(6.83 KB)
📄
usb_debug.c
(10.43 KB)
📄
usb_debug.h
(3.23 KB)
📄
usb_dev.c
(51.38 KB)
📄
usb_dev.h
(5.12 KB)
📄
usb_device.c
(77.7 KB)
📄
usb_device.h
(11.68 KB)
📄
usb_dynamic.c
(4.74 KB)
📄
usb_dynamic.h
(2.5 KB)
📄
usb_endian.h
(3.6 KB)
📄
usb_error.c
(3.69 KB)
📄
usb_fdt_support.c
(5.84 KB)
📄
usb_fdt_support.h
(2.06 KB)
📄
usb_freebsd.h
(3.96 KB)
📄
usb_freebsd_loader.h
(3.74 KB)
📄
usb_generic.c
(52.22 KB)
📄
usb_generic.h
(1.66 KB)
📄
usb_handle_request.c
(18.78 KB)
📄
usb_hid.c
(4.59 KB)
📄
usb_hub.c
(72.44 KB)
📄
usb_hub.h
(2.98 KB)
📄
usb_hub_acpi.c
(15.4 KB)
📄
usb_hub_private.h
(2.73 KB)
📄
usb_if.m
(2.27 KB)
📄
usb_ioctl.h
(12.01 KB)
📄
usb_lookup.c
(4.59 KB)
📄
usb_mbuf.c
(3.08 KB)
📄
usb_mbuf.h
(3.04 KB)
📄
usb_msctest.c
(27.07 KB)
📄
usb_msctest.h
(2.32 KB)
📄
usb_parse.c
(9.2 KB)
📄
usb_pci.h
(1.68 KB)
📄
usb_pf.c
(13.22 KB)
📄
usb_pf.h
(4.85 KB)
📄
usb_process.c
(14.31 KB)
📄
usb_process.h
(3.01 KB)
📄
usb_request.c
(60.92 KB)
📄
usb_request.h
(5.09 KB)
📄
usb_transfer.c
(91.06 KB)
📄
usb_transfer.h
(7.59 KB)
📄
usb_util.c
(6.04 KB)
📄
usb_util.h
(1.62 KB)
📄
usbdevs
(201.48 KB)
📄
usbdi.h
(24.3 KB)
📄
usbdi_util.h
(3.97 KB)
📄
usbhid.h
(3.26 KB)
📁
video
📁
wlan
Editing: usb_fdt_support.c
/*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2019 Ian Lepore <ian@FreeBSD.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/condvar.h> #include <dev/fdt/fdt_common.h> #include <dev/ofw/ofw_bus_subr.h> #include <dev/ofw/openfirm.h> #include <dev/usb/usb.h> #include <dev/usb/usbdi.h> #include <dev/usb/usb_process.h> #include <dev/usb/usb_busdma.h> #include <dev/usb/usb_controller.h> #include <dev/usb/usb_bus.h> #include <dev/usb/usb_device.h> #include <dev/usb/usb_freebsd.h> #include <dev/usb/usb_fdt_support.h> #include <dev/usb/net/usb_ethernet.h> /* * Define a constant for allocating an array pointers to serve as a stack of * devices between the controller and any arbitrary device on the bus. The * stack ends with the device itself, so add 1 to the max hub nesting depth. */ #define MAX_UDEV_NEST (MAX(USB_HUB_MAX_DEPTH, USB_SS_HUB_DEPTH_MAX) + 1) static phandle_t find_udev_in_children(phandle_t parent, struct usb_device *udev) { phandle_t child; ssize_t proplen; uint32_t port; char compat[16]; /* big enough for "usb1234,abcd" */ /* * USB device nodes in FDT have a compatible string of "usb" followed by * the vendorId,productId rendered in hex. The port number is encoded * in the standard 'reg' property; it is one-based in the FDT data, but * usb_device.port_index is zero-based. To uniquely identify a device, * both the compatible string and the port number must match. */ snprintf(compat, sizeof(compat), "usb%x,%x", UGETW(udev->ddesc.idVendor), UGETW(udev->ddesc.idProduct)); for (child = OF_child(parent); child != 0; child = OF_peer(child)) { if (!ofw_bus_node_is_compatible(child, compat)) continue; proplen = OF_getencprop(child, "reg", &port, sizeof(port)); if (proplen != sizeof(port)) continue; if (port == (udev->port_index + 1)) return (child); } return (-1); } static bool is_valid_mac_addr(uint8_t *addr) { /* * All-bits-zero and all-bits-one are a couple common cases of what * might get read from unprogrammed eeprom or OTP data, weed them out. */ if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0x00) return (false); if ((addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff) return (false); return (true); } int usb_fdt_get_mac_addr(device_t dev, struct usb_ether* ue) { phandle_t node; ssize_t i, proplen; uint8_t mac[sizeof(ue->ue_eaddr)]; static const char *properties[] = { "mac-address", "local-mac-address" }; if ((node = usb_fdt_get_node(ue->ue_dev, ue->ue_udev)) == -1) return (ENXIO); for (i = 0; i < nitems(properties); ++i) { proplen = OF_getprop(node, properties[i], mac, sizeof(mac)); if (proplen == sizeof(mac) && is_valid_mac_addr(mac)) { memcpy(ue->ue_eaddr, mac, sizeof(ue->ue_eaddr)); return (0); } } return (ENXIO); } phandle_t usb_fdt_get_node(device_t dev, struct usb_device *udev) { struct usb_device *ud; struct usb_device *udev_stack[MAX_UDEV_NEST]; phandle_t controller_node, node; int idx; /* * Start searching at the controller node. The usb_device links to the * bus, and its parent is the controller. If we can't get the * controller node, the requesting device cannot be in the fdt data. */ if ((controller_node = ofw_bus_get_node(udev->bus->parent)) == -1) return (-1); /* * Walk up the usb hub ancestor hierarchy, building a stack of devices * that begins with the requesting device and includes all the hubs * between it and the controller, NOT including the root hub (the FDT * bindings treat the controller and root hub as the same thing). */ for (ud = udev, idx = 0; ud->parent_hub != NULL; ud = ud->parent_hub) { KASSERT(idx < nitems(udev_stack), ("Too many hubs")); udev_stack[idx++] = ud; } /* * Now walk down the stack of udevs from the controller to the * requesting device, and also down the hierarchy of nested children of * the controller node in the fdt data. At each nesting level of fdt * data look for a child node whose properties match the vID,pID,portIdx * tuple for the udev at the corresponding layer of the udev stack. As * long as we keep matching up child nodes with udevs, loop and search * within the children of the just-found child for the next-deepest hub. * If at any level we fail to find a matching node, stop searching and * return. When we hit the end of the stack (the requesting device) we * return whatever the result was for the search at that nesting level. */ for (node = controller_node;;) { node = find_udev_in_children(node, udev_stack[--idx]); if (idx == 0 || node == -1) break; } return (node); }
Upload File
Create Folder