From patchwork Thu Nov 12 16:59:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 543548 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 47644140134 for ; Fri, 13 Nov 2015 04:01:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=fxYE0QX+; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3C5994B948; Thu, 12 Nov 2015 18:00:21 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id raVC_526uadr; Thu, 12 Nov 2015 18:00:21 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A255A4B94B; Thu, 12 Nov 2015 17:59:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 57CCA4B926 for ; Thu, 12 Nov 2015 17:59:51 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NrGb12G0oZ2H for ; Thu, 12 Nov 2015 17:59:51 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) by theia.denx.de (Postfix) with ESMTPS id 14D6B4B8BE for ; Thu, 12 Nov 2015 17:59:44 +0100 (CET) Received: by igl9 with SMTP id 9so101512467igl.0 for ; Thu, 12 Nov 2015 08:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=pJ3g+WPP0aSg2u54yPyNK7Lu4Pbv7wf8PEij1XhitJI=; b=fxYE0QX+4ucf/s07Yg03Ot9G3wuGjVosiJaoP8WtgCVdD7pSfs+iN6Kiu36YxfCsoD LQAhy10cn/usvp4J3+CsN/2BsP/7SmYjukI6Ir2wWBTFsAYxHV+zJNRdoqass8q5mFU8 vgJi+7NSy73Rj9ouRic/wCO4Qb6miMFb3j9CiwIF/+jOp9omZz/7y1afz9GYEiVT0kKi AdkdZWzkHnFUaAYeiai2gDIV+xp/jBdzXAtPOKVUTDOty02s1GKxYoZGHS7dLo/nTjYZ HAyE87gNahomfXJ6P2TGBT3P2pikQqmmMinozN666WCIp9ykBFg8gG03SvC+1Sfa39Vk MXrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=pJ3g+WPP0aSg2u54yPyNK7Lu4Pbv7wf8PEij1XhitJI=; b=FzPd91DdstyXUgAUcGqhBFhmLiZkiwIK/BCCsZjIQmBM/K8lrs2R9EA6cKVY6dm/Uu h7lsCvago4aUet2SMJXY/Cn2CGxqEQWXf8OkAtq/X2c0W40jXQ5oXP18erSaBPPQxLfv zbaJ44/gp+N+NktkaQ/x1RZXSRR4u60+0kh1QPxF34tDLyYeh9sTKWxuqlhYzURlVKGm GCgubxQItSw/9gXjugDEzVDFaVl6BKxWA/pCvizwtogznKBoGjMdYeEj9FlHXeMwZg28 OH/eW6cuZIH2/FHahhKuGdesD2vEJThvkZEsCKxoDk9pGy7Gf40t6OU8/ulDpo2Kdh/z 87WA== X-Gm-Message-State: ALoCoQkfCbNetVZ6Mskj3Ce0lnNNEEU7bJ/5x62PlTEctr8/Iu2kikTZRT9sXVmM7X9AwkXo4SZV X-Received: by 10.50.66.69 with SMTP id d5mr35137617igt.30.1447347582589; Thu, 12 Nov 2015 08:59:42 -0800 (PST) Received: from kaki.bld.corp.google.com ([2620:0:1005:1100:6084:288e:1172:8ae5]) by smtp.gmail.com with ESMTPSA id or1sm5245756igb.4.2015.11.12.08.59.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Nov 2015 08:59:41 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 6DFD6220BB3; Thu, 12 Nov 2015 09:59:37 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 12 Nov 2015 09:59:31 -0700 Message-Id: <1447347572-4382-8-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1447347572-4382-2-git-send-email-sjg@chromium.org> References: <1447347572-4382-2-git-send-email-sjg@chromium.org> Cc: Stephen Warren , Tom Warren Subject: [U-Boot] [PATCH v3 7/8] dm: pci: Add a function to find the regions for a PCI bus X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This function looks up the controller and returns a pointer to each region type. Signed-off-by: Simon Glass Acked-by: Stephen Warren --- Changes in v3: None Changes in v2: None drivers/pci/pci-uclass.c | 30 ++++++++++++++++++++++++++++++ include/pci.h | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index f3f5f00..5fe3072 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -974,6 +974,36 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset, return value; } +int pci_get_regions(struct udevice *dev, struct pci_region **iop, + struct pci_region **memp, struct pci_region **prefp) +{ + struct udevice *bus = pci_get_controller(dev); + struct pci_controller *hose = dev_get_uclass_priv(bus); + int i; + + *iop = NULL; + *memp = NULL; + *prefp = NULL; + for (i = 0; i < hose->region_count; i++) { + switch (hose->regions[i].flags) { + case PCI_REGION_IO: + if (!*iop || (*iop)->size < hose->regions[i].size) + *iop = hose->regions + i; + break; + case PCI_REGION_MEM: + if (!*memp || (*memp)->size < hose->regions[i].size) + *memp = hose->regions + i; + break; + case (PCI_REGION_MEM | PCI_REGION_PREFETCH): + if (!*prefp || (*prefp)->size < hose->regions[i].size) + *prefp = hose->regions + i; + break; + } + } + + return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL); +} + UCLASS_DRIVER(pci) = { .id = UCLASS_PCI, .name = "pci", diff --git a/include/pci.h b/include/pci.h index f3dda70..9c19482 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1131,6 +1131,18 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset, struct udevice *pci_get_controller(struct udevice *dev); /** + * pci_get_regions() - obtain pointers to all the region types + * + * @dev: Device to check + * @iop: Returns a pointer to the I/O region, or NULL if none + * @memp: Returns a pointer to the memory region, or NULL if none + * @prefp: Returns a pointer to the pre-fetch region, or NULL if none + * @return the number of non-NULL regions returned, normally 3 + */ +int pci_get_regions(struct udevice *dev, struct pci_region **iop, + struct pci_region **memp, struct pci_region **prefp); + +/** * struct dm_pci_emul_ops - PCI device emulator operations */ struct dm_pci_emul_ops {