Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>.
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node)
58 /* The 'name' property is considered mandatory. */
59 if ((OF_getprop_alloc(node, "name", (void **)&obd->obd_name)) == -1)
61 OF_getprop_alloc(node, "compatible", (void **)&obd->obd_compat);
62 OF_getprop_alloc(node, "device_type", (void **)&obd->obd_type);
63 OF_getprop_alloc(node, "model", (void **)&obd->obd_model);
64 OF_getprop_alloc(node, "status", (void **)&obd->obd_status);
65 obd->obd_node = node;
75 if (obd->obd_compat != NULL)
76 free(obd->obd_compat, M_OFWPROP);
77 if (obd->obd_model != NULL)
78 free(obd->obd_model, M_OFWPROP);
79 if (obd->obd_name != NULL)
80 free(obd->obd_name, M_OFWPROP);
81 if (obd->obd_type != NULL)
82 free(obd->obd_type, M_OFWPROP);
83 if (obd->obd_status != NULL)
84 free(obd->obd_status, M_OFWPROP);
88 ofw_bus_gen_child_pnpinfo(device_t cbdev, device_t child, struct sbuf *sb)
91 if (!ofw_bus_status_okay(child))
94 if (ofw_bus_get_name(child) != NULL) {
95 sbuf_printf(sb, "name=%s ", ofw_bus_get_name(child));
98 if (ofw_bus_get_compat(child) != NULL) {
99 sbuf_printf(sb, "compat=%s ", ofw_bus_get_compat(child));
106 ofw_bus_gen_get_device_path(device_t cbdev, device_t child, const char *locator,
112 rv = bus_generic_get_device_path(cbdev, child, locator, sb);
114 sbuf_printf(sb, "/%s", ofw_bus_get_name(child));
118 return (bus_generic_get_device_path(cbdev, child, locator, sb));
129 return (obd->obd_compat);
140 return (obd->obd_model);
151 return (obd->obd_name);
161 return ((phandle_t)-1);
162 return (obd->obd_node);
173 return (obd->obd_type);
185 return (obd->obd_status);
202 ofw_bus_node_status_okay(phandle_t node)
207 len = OF_getproplen(node, "status");
211 OF_getprop(node, "status", status, OFW_STATUS_LEN);
236 /* Slide to the next sub-string. */
239 len -= l;
246 ofw_bus_node_is_compatible(phandle_t node, const char *compatstr)
251 if ((len = OF_getproplen(node, "compatible")) <= 0)
256 if (OF_getprop(node, "compatible", compat, OFW_COMPAT_LEN) < 0)
267 phandle_t node;
274 if ((node = ofw_bus_get_node(dev)) == -1)
278 if ((len = OF_getproplen(node, "compatible")) <= 0)
308 for (; compat->ocd_str != NULL; ++compat) {
309 if (ofw_bus_is_compatible(dev, compat->ocd_str))
319 phandle_t node;
321 if ((node = ofw_bus_get_node(dev)) == -1)
324 return (OF_hasprop(node, propname));
328 ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz)
333 if (OF_getencprop(node, "#address-cells", &addrc, sizeof(addrc)) == -1)
335 ii->opi_addrc = addrc * sizeof(pcell_t);
337 ii->opi_imapsz = OF_getencprop_alloc(node, "interrupt-map",
338 (void **)&ii->opi_imap);
339 if (ii->opi_imapsz > 0) {
340 msksz = OF_getencprop_alloc(node, "interrupt-map-mask",
341 (void **)&ii->opi_imapmsk);
343 * Failure to get the mask is ignored; a full mask is used
346 if (msksz != -1 && msksz != ii->opi_addrc + intrsz)
347 panic("ofw_bus_setup_iinfo: bad interrupt-map-mask "
348 "property!");
353 ofw_bus_lookup_imap(phandle_t node, struct ofw_bus_iinfo *ii, void *reg,
360 if (ii->opi_imapsz <= 0)
362 KASSERT(regsz >= ii->opi_addrc,
364 regsz, ii->opi_addrc));
365 if (node != -1) {
366 rv = OF_getencprop(node, "reg", reg, regsz);
368 panic("ofw_bus_lookup_imap: cannot get reg property");
370 return (ofw_bus_search_intrmap(pintr, pintrsz, reg, ii->opi_addrc,
371 ii->opi_imap, ii->opi_imapsz, ii->opi_imapmsk, maskbuf, mintr,
376 * Map an interrupt using the firmware reg, interrupt-map and
377 * interrupt-map-mask properties.
378 * The interrupt property to be mapped must be of size intrsz, and pointed to
379 * by intr. The regs property of the node for which the mapping is done must
380 * be passed as regs. This property is an array of register specifications;
381 * the size of the address part of such a specification must be passed as
382 * physsz. Only the first element of the property is used.
384 * imapmsk is a pointer to the interrupt-map-mask property, which must have
385 * a size of physsz + intrsz; it may be NULL, in which case a full mask is
387 * maskbuf must point to a buffer of length physsz + intrsz.
388 * The interrupt is returned in result, which must point to a buffer of length
390 * Returns number of cells in the interrupt if a mapping was found, 0 otherwise.
425 * CHRP-derived OF bindings, including ePAPR-compliant FDTs,
429 "#address-cells", &paddrsz, sizeof(paddrsz)) == -1)
435 "#interrupt-cells", &pintrsz, sizeof(pintrsz)) == -1)
452 i -= tsz;
458 ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent,
467 len = OF_getencprop_alloc_multi(node, "msi-map", sizeof(*map),
472 OF_getencprop(node, "msi-parent", msi_parent,
482 OF_getencprop(node, "msi-map-mask", &mask, sizeof(mask));
498 *msi_rid = masked_rid - rid_base + msi_base;
509 ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu_parent,
517 len = OF_getencprop_alloc_multi(node, "iommu-map", sizeof(*map),
524 OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask));
540 *iommu_rid = masked_rid - rid_base + iommu_base;
551 ofw_bus_reg_to_rl_helper(device_t dev, phandle_t node, pcell_t acells, pcell_t scells,
563 ret = OF_getprop_alloc(node, "name", (void **)&name);
564 if (ret == -1)
567 ret = OF_getencprop_alloc_multi(node, reg_source, sizeof(*reg),
569 nreg = (ret == -1) ? 0 : ret;
573 device_printf(dev, "Malformed reg property on <%s>\n",
588 /* Skip the dummy reg property of glue devices like ssm(4). */
591 phys, phys + size - 1, size);
600 ofw_bus_reg_to_rl(device_t dev, phandle_t node, pcell_t acells, pcell_t scells,
604 return (ofw_bus_reg_to_rl_helper(dev, node, acells, scells, rl, "reg"));
608 ofw_bus_assigned_addresses_to_rl(device_t dev, phandle_t node, pcell_t acells,
612 return (ofw_bus_reg_to_rl_helper(dev, node, acells, scells,
613 rl, "assigned-addresses"));
617 * Get interrupt parent for given node.
621 ofw_bus_find_iparent(phandle_t node)
625 if (OF_searchencprop(node, "interrupt-parent", &iparent,
626 sizeof(iparent)) == -1) {
627 for (iparent = node; iparent != 0;
629 if (OF_hasprop(iparent, "interrupt-controller"))
638 ofw_bus_intr_to_rl(device_t dev, phandle_t node,
646 nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
649 iparent = ofw_bus_find_iparent(node);
651 device_printf(dev, "No interrupt-parent found, "
653 iparent = OF_parent(node);
657 "#interrupt-cells", &icells, sizeof(icells)) == -1) {
658 device_printf(dev, "Missing #interrupt-cells "
659 "property, assuming <1>\n");
663 device_printf(dev, "Invalid #interrupt-cells property "
669 nintr = OF_getencprop_alloc_multi(node, "interrupts-extended",
681 "#interrupt-cells", &icells, sizeof(icells)) == -1) {
682 device_printf(dev, "Missing #interrupt-cells "
683 "property\n");
688 device_printf(dev, "Invalid #interrupt-cells "
689 "property value <%d>\n", icells);
704 ofw_bus_intr_by_rid(device_t dev, phandle_t node, int wanted_rid,
712 nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
715 iparent = ofw_bus_find_iparent(node);
717 device_printf(dev, "No interrupt-parent found, "
719 iparent = OF_parent(node);
723 "#interrupt-cells", &icells, sizeof(icells)) == -1) {
724 device_printf(dev, "Missing #interrupt-cells "
725 "property, assuming <1>\n");
729 device_printf(dev, "Invalid #interrupt-cells property "
735 nintr = OF_getencprop_alloc_multi(node, "interrupts-extended",
747 "#interrupt-cells", &icells, sizeof(icells)) == -1) {
748 device_printf(dev, "Missing #interrupt-cells "
749 "property\n");
754 device_printf(dev, "Invalid #interrupt-cells "
755 "property value <%d>\n", icells);
779 phandle_t child;
781 for (child = OF_child(start); child != 0; child = OF_peer(child)) {
782 ret = OF_getprop_alloc(child, "name", (void **)&name);
783 if (ret == -1)
787 return (child);
797 ofw_bus_find_compatible(phandle_t node, const char *onecompat)
799 phandle_t child, ret;
802 * Traverse all children of 'start' node, and find first with
803 * matching 'compatible' property.
805 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
806 if (ofw_bus_node_is_compatible(child, onecompat) != 0)
807 return (child);
809 ret = ofw_bus_find_compatible(child, onecompat);
817 * @brief Return child of bus whose phandle is node
819 * A direct child of @p will be returned if it its phandle in the
820 * OFW tree is @p node. Otherwise, NULL is returned.
823 * @param node The phandle_t to look for.
826 ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node)
828 device_t *children, retval, child;
832 * Nothing can match the flag value for no node.
834 if (node == -1)
838 * Search the children for a match. We microoptimize
839 * a bit by not using ofw_bus_get since we already know
846 child = children[i];
847 if (OFW_BUS_GET_NODE(bus, child) == node) {
848 retval = child;
858 * Parse property that contain list of xrefs and values
861 * node - consumers device node
862 * list_name - name of parsed list - "clocks"
863 * cells_name - name of size property - "#clock-cells"
864 * idx - the index of the requested list entry, or, if -1, an indication
867 * producer - handle of producer
868 * ncells - number of cells in result or the number of items in the list when
869 * idx == -1.
870 * cells - array of decoded cells
873 ofw_bus_parse_xref_list_internal(phandle_t node, const char *list_name,
883 nelems = OF_getencprop_alloc_multi(node, list_name, sizeof(*elems),
887 rv = (idx == -1) ? 0 : ENOENT;
891 cells_name, &pcells, sizeof(pcells)) == -1) {
892 printf("Missing %s property\n", cells_name);
898 printf("Invalid %s property value <%d>\n", cells_name,
916 if (idx == -1 && rv == 0)
922 * Parse property that contain list of xrefs and values
925 * node - consumers device node
926 * list_name - name of parsed list - "clocks"
927 * cells_name - name of size property - "#clock-cells"
928 * idx - the index of the requested list entry (>= 0)
930 * producer - handle of producer
931 * ncells - number of cells in result
932 * cells - array of decoded cells
935 ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name,
943 return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name,
948 * Parse property that contain list of xrefs and values
952 * node - consumers device node
953 * list_name - name of parsed list - "clocks"
954 * cells_name - name of size property - "#clock-cells"
956 * count - number of items in list
959 ofw_bus_parse_xref_list_get_length(phandle_t node, const char *list_name,
963 return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name,
964 -1, NULL, count, NULL));
968 * Find index of string in string list property (case sensitive).
971 ofw_bus_find_string_index(phandle_t node, const char *list_name,
978 nelems = OF_getprop_alloc(node, list_name, (void **)&elems);
998 * Create zero terminated array of strings from string list property.
1001 ofw_bus_string_list_to_array(phandle_t node, const char *list_name,
1009 nelems = OF_getprop_alloc(node, list_name, (void **)&elems);