\hypertarget{usb__fdt__support_8c_source}{}\doxysection{usb\+\_\+fdt\+\_\+support.\+c}
\label{usb__fdt__support_8c_source}\index{dev/usb/usb\_fdt\_support.c@{dev/usb/usb\_fdt\_support.c}}
\mbox{\hyperlink{usb__fdt__support_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2019 Ian Lepore <ian@FreeBSD.org>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00005}00005 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00006}00006 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00007}00007 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00008}00008 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00009}00009 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00010}00010 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00011}00011 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00012}00012 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00013}00013 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00014}00014 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00015}00015 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00016}00016 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00017}00017 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00018}00018 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00019}00019 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00020}00020 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00021}00021 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00022}00022 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00023}00023 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00024}00024 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00025}00025 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00026}00026 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00027}00027 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00028}00028 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00029}\mbox{\hyperlink{usb__fdt__support_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00029}} \mbox{\hyperlink{usb__fdt__support_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00030}00030 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00031}00031 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/condvar.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00033}00033 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <dev/fdt/fdt\_common.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <dev/ofw/ofw\_bus\_subr.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <dev/ofw/openfirm.h>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00037}00037 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb_8h}{dev/usb/usb.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usbdi_8h}{dev/usb/usbdi.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__process_8h}{dev/usb/usb\_process.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__busdma_8h}{dev/usb/usb\_busdma.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__controller_8h}{dev/usb/usb\_controller.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__bus_8h}{dev/usb/usb\_bus.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__device_8h}{dev/usb/usb\_device.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__freebsd_8h}{dev/usb/usb\_freebsd.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__fdt__support_8h}{dev/usb/usb\_fdt\_support.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00047}00047 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{usb__ethernet_8h}{dev/usb/net/usb\_ethernet.h}}>}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00048}00048 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00049}00049 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00050}00050 \textcolor{comment}{ * Define a constant for allocating an array pointers to serve as a stack of}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00051}00051 \textcolor{comment}{ * devices between the controller and any arbitrary device on the bus.  The}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00052}00052 \textcolor{comment}{ * stack ends with the device itself, so add 1 to the max hub nesting depth.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00053}00053 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00054}\mbox{\hyperlink{usb__fdt__support_8c_ae73a54bedeea15969871247292d739f8}{00054}} \textcolor{preprocessor}{\#define MAX\_UDEV\_NEST   (MAX(USB\_HUB\_MAX\_DEPTH, USB\_SS\_HUB\_DEPTH\_MAX) + 1)}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00055}00055 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00056}00056 \textcolor{keyword}{static} phandle\_t}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00057}\mbox{\hyperlink{usb__fdt__support_8c_a7644bcee15703465cf864f3541c0893f}{00057}} \mbox{\hyperlink{usb__fdt__support_8c_a7644bcee15703465cf864f3541c0893f}{find\_udev\_in\_children}}(phandle\_t parent, \textcolor{keyword}{struct} \mbox{\hyperlink{structusb__device}{usb\_device}} *udev)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00058}00058 \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00059}00059         phandle\_t child;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00060}00060         ssize\_t proplen;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00061}00061         uint32\_t port;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00062}00062         \textcolor{keywordtype}{char} compat[16]; \textcolor{comment}{/* big enough for "{}usb1234,abcd"{} */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00063}00063 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00064}00064         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00065}00065 \textcolor{comment}{         * USB device nodes in FDT have a compatible string of "{}usb"{} followed by}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00066}00066 \textcolor{comment}{         * the vendorId,productId rendered in hex.  The port number is encoded}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00067}00067 \textcolor{comment}{         * in the standard 'reg' property; it is one-\/based in the FDT data, but}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00068}00068 \textcolor{comment}{         * usb\_device.port\_index is zero-\/based.  To uniquely identify a device,}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00069}00069 \textcolor{comment}{         * both the compatible string and the port number must match.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00070}00070 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00071}00071         snprintf(compat, \textcolor{keyword}{sizeof}(compat), \textcolor{stringliteral}{"{}usb\%x,\%x"{}},}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00072}00072             \mbox{\hyperlink{usb__endian_8h_aa3860f9452db3a5d865cc943e2f01829}{UGETW}}(udev-\/>\mbox{\hyperlink{structusb__device_a6fa6ffff7bff082394d16b2b05d66cdf}{ddesc}}.\mbox{\hyperlink{structusb__device__descriptor_ac2a3d9b7e40bde975d26dd83d8350485}{idVendor}}), \mbox{\hyperlink{usb__endian_8h_aa3860f9452db3a5d865cc943e2f01829}{UGETW}}(udev-\/>\mbox{\hyperlink{structusb__device_a6fa6ffff7bff082394d16b2b05d66cdf}{ddesc}}.\mbox{\hyperlink{structusb__device__descriptor_a09e74f08b2dc62817b2c3eb6a631883e}{idProduct}}));}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00073}00073         \textcolor{keywordflow}{for} (child = OF\_child(parent); child != 0; child = OF\_peer(child)) \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00074}00074                 \textcolor{keywordflow}{if} (!ofw\_bus\_node\_is\_compatible(child, compat))}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00075}00075                         \textcolor{keywordflow}{continue};}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00076}00076                 proplen = OF\_getencprop(child, \textcolor{stringliteral}{"{}reg"{}}, \&port, \textcolor{keyword}{sizeof}(port));}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00077}00077                 \textcolor{keywordflow}{if} (proplen != \textcolor{keyword}{sizeof}(port))}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00078}00078                         \textcolor{keywordflow}{continue};}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00079}00079                 \textcolor{keywordflow}{if} (port == (udev-\/>\mbox{\hyperlink{structusb__device_a260e4b4f7f69833bcb8267f4a80b5a5f}{port\_index}} + 1))}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00080}00080                         \textcolor{keywordflow}{return} (child);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00081}00081         \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00082}00082         \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00083}00083 \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00084}00084 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00085}00085 \textcolor{keyword}{static} \textcolor{keywordtype}{bool}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00086}\mbox{\hyperlink{usb__fdt__support_8c_a92abde9a396e65ba42039c7abe0cc35a}{00086}} \mbox{\hyperlink{usb__fdt__support_8c_a92abde9a396e65ba42039c7abe0cc35a}{is\_valid\_mac\_addr}}(uint8\_t *addr)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00087}00087 \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00088}00088 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00089}00089         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00090}00090 \textcolor{comment}{         * All-\/bits-\/zero and all-\/bits-\/one are a couple common cases of what}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00091}00091 \textcolor{comment}{         * might get read from unprogrammed eeprom or OTP data, weed them out.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00092}00092 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00093}00093         \textcolor{keywordflow}{if} ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0x00)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00094}00094                 \textcolor{keywordflow}{return} (\textcolor{keyword}{false});}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00095}00095         \textcolor{keywordflow}{if} ((addr[0] \& addr[1] \& addr[2] \& addr[3] \& addr[4] \& addr[5]) == 0xff)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00096}00096                 \textcolor{keywordflow}{return} (\textcolor{keyword}{false});}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00097}00097         \textcolor{keywordflow}{return} (\textcolor{keyword}{true});}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00098}00098 \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00099}00099 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00100}00100 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00101}\mbox{\hyperlink{usb__fdt__support_8c_a0a62eef292afd13e4156bebb48a8bd4a}{00101}} \mbox{\hyperlink{usb__fdt__support_8c_a0a62eef292afd13e4156bebb48a8bd4a}{usb\_fdt\_get\_mac\_addr}}(device\_t dev, \textcolor{keyword}{struct} \mbox{\hyperlink{structusb__ether}{usb\_ether}}* ue)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00102}00102 \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00103}00103         phandle\_t node;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00104}00104         ssize\_t i, proplen;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00105}00105         uint8\_t mac[\textcolor{keyword}{sizeof}(ue-\/>\mbox{\hyperlink{structusb__ether_ad1e7ad3609b27b7adab9d6086a20059a}{ue\_eaddr}})];}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00106}00106         \textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *properties[] = \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00107}00107             \textcolor{stringliteral}{"{}mac-\/address"{}},}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00108}00108             \textcolor{stringliteral}{"{}local-\/mac-\/address"{}}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00109}00109         \};}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00110}00110 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00111}00111         \textcolor{keywordflow}{if} ((node = \mbox{\hyperlink{usb__fdt__support_8c_ab59b59b51cc78ce83605377c9e95e9f7}{usb\_fdt\_get\_node}}(ue-\/>\mbox{\hyperlink{structusb__ether_ade8818fa2f6daf9addc42c3e39027515}{ue\_dev}}, ue-\/>\mbox{\hyperlink{structusb__ether_a9038cbb427aa5dfd094db8d183f909cc}{ue\_udev}})) == -\/1)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00112}00112                 \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00113}00113         \textcolor{keywordflow}{for} (i = 0; i < nitems(properties); ++i) \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00114}00114                 proplen = OF\_getprop(node, properties[i], mac, \textcolor{keyword}{sizeof}(mac));}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00115}00115                 \textcolor{keywordflow}{if} (proplen == \textcolor{keyword}{sizeof}(mac) \&\& \mbox{\hyperlink{usb__fdt__support_8c_a92abde9a396e65ba42039c7abe0cc35a}{is\_valid\_mac\_addr}}(mac)) \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00116}00116                         memcpy(ue-\/>\mbox{\hyperlink{structusb__ether_ad1e7ad3609b27b7adab9d6086a20059a}{ue\_eaddr}}, mac, \textcolor{keyword}{sizeof}(ue-\/>\mbox{\hyperlink{structusb__ether_ad1e7ad3609b27b7adab9d6086a20059a}{ue\_eaddr}}));}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00117}00117                         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00118}00118                 \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00119}00119         \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00120}00120         \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00121}00121 \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00122}00122 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00123}00123 phandle\_t}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00124}\mbox{\hyperlink{usb__fdt__support_8c_ab59b59b51cc78ce83605377c9e95e9f7}{00124}} \mbox{\hyperlink{usb__fdt__support_8c_ab59b59b51cc78ce83605377c9e95e9f7}{usb\_fdt\_get\_node}}(device\_t dev, \textcolor{keyword}{struct} \mbox{\hyperlink{structusb__device}{usb\_device}} *udev)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00125}00125 \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00126}00126         \textcolor{keyword}{struct }\mbox{\hyperlink{structusb__device}{usb\_device}} *ud;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00127}00127         \textcolor{keyword}{struct }\mbox{\hyperlink{structusb__device}{usb\_device}} *udev\_stack[\mbox{\hyperlink{usb__fdt__support_8c_ae73a54bedeea15969871247292d739f8}{MAX\_UDEV\_NEST}}];}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00128}00128         phandle\_t controller\_node, node;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00129}00129         \textcolor{keywordtype}{int} idx;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00130}00130 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00131}00131         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00132}00132 \textcolor{comment}{         * Start searching at the controller node.  The usb\_device links to the}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00133}00133 \textcolor{comment}{         * bus, and its parent is the controller.  If we can't get the}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00134}00134 \textcolor{comment}{         * controller node, the requesting device cannot be in the fdt data.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00135}00135 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00136}00136         \textcolor{keywordflow}{if} ((controller\_node = ofw\_bus\_get\_node(udev-\/>\mbox{\hyperlink{structusb__device_a532e474ebc2a6bfa9512e6fa1aaedf3c}{bus}}-\/>\mbox{\hyperlink{structusb__bus_a7855a7fc5c4b3f5289323c7743c6a975}{parent}})) == -\/1)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00137}00137                 \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00138}00138 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00139}00139         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00140}00140 \textcolor{comment}{         * Walk up the usb hub ancestor hierarchy, building a stack of devices}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00141}00141 \textcolor{comment}{         * that begins with the requesting device and includes all the hubs}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00142}00142 \textcolor{comment}{         * between it and the controller, NOT including the root hub (the FDT}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00143}00143 \textcolor{comment}{         * bindings treat the controller and root hub as the same thing).}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00144}00144 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00145}00145         \textcolor{keywordflow}{for} (ud = udev, idx = 0; ud-\/>\mbox{\hyperlink{structusb__device_aa35d4d1b88f22abb34d30e9762153e0b}{parent\_hub}} != NULL; ud = ud-\/>\mbox{\hyperlink{structusb__device_aa35d4d1b88f22abb34d30e9762153e0b}{parent\_hub}}) \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00146}00146                 KASSERT(idx < nitems(udev\_stack), (\textcolor{stringliteral}{"{}Too many hubs"{}}));}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00147}00147                 udev\_stack[idx++] = ud;}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00148}00148         \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00149}00149 }
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00150}00150         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00151}00151 \textcolor{comment}{         * Now walk down the stack of udevs from the controller to the}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00152}00152 \textcolor{comment}{         * requesting device, and also down the hierarchy of nested children of}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00153}00153 \textcolor{comment}{         * the controller node in the fdt data.  At each nesting level of fdt}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00154}00154 \textcolor{comment}{         * data look for a child node whose properties match the vID,pID,portIdx}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00155}00155 \textcolor{comment}{         * tuple for the udev at the corresponding layer of the udev stack.  As}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00156}00156 \textcolor{comment}{         * long as we keep matching up child nodes with udevs, loop and search}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00157}00157 \textcolor{comment}{         * within the children of the just-\/found child for the next-\/deepest hub.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00158}00158 \textcolor{comment}{         * If at any level we fail to find a matching node, stop searching and}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00159}00159 \textcolor{comment}{         * return.  When we hit the end of the stack (the requesting device) we}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00160}00160 \textcolor{comment}{         * return whatever the result was for the search at that nesting level.}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00161}00161 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00162}00162         \textcolor{keywordflow}{for} (node = controller\_node;;) \{}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00163}00163                 node = \mbox{\hyperlink{usb__fdt__support_8c_a7644bcee15703465cf864f3541c0893f}{find\_udev\_in\_children}}(node, udev\_stack[-\/-\/idx]);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00164}00164                 \textcolor{keywordflow}{if} (idx == 0 || node == -\/1)}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00165}00165                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00166}00166         \}}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00167}00167         \textcolor{keywordflow}{return} (node);}
\DoxyCodeLine{\Hypertarget{usb__fdt__support_8c_source_l00168}00168 \}}

\end{DoxyCode}
