/* $NetBSD: amdnb_misc.c,v 1.5 2021/08/07 16:19:07 thorpej Exp $ */
/*
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christoph Egger.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD)
return 0;
switch (PCI_PRODUCT(pa->pa_id)) {
case PCI_PRODUCT_AMD_AMD64_MISC:
case PCI_PRODUCT_AMD_AMD64_F10_MISC:
case PCI_PRODUCT_AMD_AMD64_F11_MISC:
case PCI_PRODUCT_AMD_F14_NB: /* Family 12h, too */
case PCI_PRODUCT_AMD_F15_MISC:
case PCI_PRODUCT_AMD_F16_NB:
case PCI_PRODUCT_AMD_F16_30_NB:
break;
default:
return 0;
}
return 2; /* supercede pchb(4) */
}
static int
amdnb_misc_search(device_t parent, cfdata_t cf, const int *locs, void *aux)
{
device_t dev;
deviter_t di;
bool attach;
if (!config_probe(parent, cf, aux))
return 0;
attach = true;
/* Figure out if found child 'cf' is already attached.
* No need to attach it twice.
*/
/* XXX: I only want to iterate over the children of *this* device.
* Can we introduce a
* deviter_first_child(&di, parent, DEVITER_F_LEAVES_ONLY)
* or even better, can we introduce a query function that returns
* if a child is already attached?
*/
for (dev = deviter_first(&di, DEVITER_F_LEAVES_FIRST); dev != NULL;
dev = deviter_next(&di))
{
if (device_parent(dev) != parent)
continue;
if (device_is_a(dev, cf->cf_name)) {
attach = false;
break;
}
}
deviter_release(&di);