From patchwork Mon Mar 11 09:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Yen X-Patchwork-Id: 13588468 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C057D2232A for ; Mon, 11 Mar 2024 09:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710150601; cv=none; b=UisznP3NaHy5hiQr2aX4+RKNL0zLnh+9nChV05fZcxR7bk0NP2FxdMhSat6mBBIyNhIz0pskEaWA7GfsJvGFmOyMP4JPqJkS9ny4c+262i7TF1N+PFW4E80TKyjSJx5Ydk1RDMNUu8G+t2VwKghFR9iM/o36iwPP8cksn6OHLo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710150601; c=relaxed/simple; bh=ErXM/xCqChIXuI/reXCOq5YLubZuZxj1O0AlcJ3LwU4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FGIyGaFlN17A+OV8T+qGdDmVgNDLhLImA6MRSWTyUaHIoXWn4+L9RKiVckPowhcMrn6tw6e6lEjms6KU5vcmiLrOcsjy5xxGjx4S+i3EQMzSgxb+HJR3C7uxuJDw4y5aaxBLpl8g8P3/ZHaesPCtK2dAafDbilOcDDE7AaR0u6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--howardyen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oRBU6NcT; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--howardyen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oRBU6NcT" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dce775fa8adso7169679276.1 for ; Mon, 11 Mar 2024 02:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710150599; x=1710755399; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hAGyZk4wDoLUijxbM5TEZd0Agy/9efRjEZc3xhOwTeE=; b=oRBU6NcTgVDlwR4+E5qFBTacDxzclrguf1ipSpVBd74OAD9IxGufSnZdSXwVDfr5qH 8KQCoL8ypfZKlcCSyTkLJcVWdlW/WKWqLY88pONFeFWAQvfe5cfeUoCNB20theq81QO6 FFQTEBdrgRgthP3lN+2wBv2J5dCUwhQYOgfx7yNODpXa4q8bn8zLn+uBZE8q8ozTTfoM UKTvoqYwQTLiYXjH2H3xrbzyOuSL0BKybOgDKCp7Orc24ZAE4jc4DQBgita9YrEkewMY dtN5Upk6WTSeyxpvKDKkvSBJREWaVhSC0pUKU3iwV+WB1xrqVRYIXe8t102PBkC9OcPT iEoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710150599; x=1710755399; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hAGyZk4wDoLUijxbM5TEZd0Agy/9efRjEZc3xhOwTeE=; b=r/9W4xiWSWxbDCsMM8EQoJqF20/7U0zdydebXVzEkLRZsMrCP/VGsCHt9B3KwoTYba vNh3reSDq8yXtedwrJCPCoamxl9AoGosP1/03wU/VnfjdAr1cQ0siubgslvrz3cXYt85 TipY/dHtV62u3p5mXA7V/7TW392wMS6tECor3eS/W/C8mor/0B8MRzzlwZq0+gOTZQcU wLSydUdciYb7JQ7bePX8YZbGCph4HM+vvMpKqQ3gQnlF96BhGfeLr/jEyvpf+7tXZV5M 1wsuCEjgzbbp7R41O8w9DNkrnoM6s7LkMPv5dg6+oAKKni8i53qxwkqfYoKHXeM7pKum wydQ== X-Forwarded-Encrypted: i=1; AJvYcCWLhcRpWQQ80nu5M6Vg9fOsfH+FF5HT4iI5qMvUAbD0483IW7kOeoCu9G08OzkJl6qQ3IpE6CqIujDkLMWT4IDVZYoN+/4IUjKs X-Gm-Message-State: AOJu0YxLve+N1QDNxstpZGvtO89ZdCJ5WlyWjxHb+cbIG//oALx2icJ6 79hINA/KtUKgaET5GIXV2OuIG7zXZGNK91B7bK7MFrrm2AF6mn3gQogzSagMwMnpN1aqjP2W/Yl kA7PTzFU04g15XQ== X-Google-Smtp-Source: AGHT+IE6jcflp9fRCKJ0gJHRuFbcchVasL4L61tzVdhEWWl/adPMpMiCXsQ0hTXzFp5hlU/ryT6buk71g33IePo= X-Received: from howardyen2.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:16f7]) (user=howardyen job=sendgmr) by 2002:a05:6902:10c2:b0:dc6:e1ed:bd1a with SMTP id w2-20020a05690210c200b00dc6e1edbd1amr1726976ybu.2.1710150598548; Mon, 11 Mar 2024 02:49:58 -0700 (PDT) Date: Mon, 11 Mar 2024 09:49:46 +0000 In-Reply-To: <20240311094947.3738200-1-howardyen@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240311094947.3738200-1-howardyen@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240311094947.3738200-2-howardyen@google.com> Subject: [PATCH v5 1/2] dma-coherent: add support for multi coherent rmems per dev From: Howard Yen To: gregkh@linuxfoundation.org, rafael@kernel.org, mathias.nyman@intel.com, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, andriy.shevchenko@linux.intel.com, petr.tesarik.ext@huawei.com, broonie@kernel.org, james@equiv.tech, james.clark@arm.com, masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, iommu@lists.linux.dev, Howard Yen Add support for multiple coherent rmems per device. This patch replaces original dma_mem with dma_mems list in device structure to store multiple rmems. These multiple rmems can be assigned to the device one by one by of_reserved_mem_device_init_by_idx() with the memory-region declaration in device tree as below and store the rmem to the dma_mems list. device1@0 { ... memory-region = <&reserved_mem0>, <&reserved_mem1>; ... }; When driver tries to allocate memory from the rmems, looks for the first available rmem and allocates the memory from this rmem. Then if driver removed, of_reserved_mem_device_release() needs to be invoked to release all the rmems assigned to the device. Signed-off-by: Howard Yen --- drivers/base/core.c | 3 ++ include/linux/device.h | 5 +-- kernel/dma/coherent.c | 92 +++++++++++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 36 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 14d46af40f9a..d9af38d7b870 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3108,6 +3108,9 @@ void device_initialize(struct device *dev) defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) dev->dma_coherent = dma_default_coherent; +#endif +#ifdef CONFIG_DMA_DECLARE_COHERENT + INIT_LIST_HEAD(&dev->dma_mems); #endif swiotlb_dev_init(dev); } diff --git a/include/linux/device.h b/include/linux/device.h index 97c4b046c09d..5fa15e5adbdc 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -648,7 +648,7 @@ struct device_physical_location { * @dma_parms: A low level driver may set these to teach IOMMU code about * segment limitations. * @dma_pools: Dma pools (if dma'ble device). - * @dma_mem: Internal for coherent mem override. + * @dma_mems: Internal for coherent mems. * @cma_area: Contiguous memory area for dma allocations * @dma_io_tlb_mem: Software IO TLB allocator. Not for driver use. * @dma_io_tlb_pools: List of transient swiotlb memory pools. @@ -749,8 +749,7 @@ struct device { struct list_head dma_pools; /* dma pools (if dma'ble) */ #ifdef CONFIG_DMA_DECLARE_COHERENT - struct dma_coherent_mem *dma_mem; /* internal for coherent mem - override */ + struct list_head dma_mems; /* Internal for coherent mems */ #endif #ifdef CONFIG_DMA_CMA struct cma *cma_area; /* contiguous memory area for dma diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index ff5683a57f77..f6748a3a5eb1 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -11,22 +11,16 @@ #include struct dma_coherent_mem { - void *virt_base; - dma_addr_t device_base; - unsigned long pfn_base; - int size; - unsigned long *bitmap; - spinlock_t spinlock; - bool use_dev_dma_pfn_offset; + struct list_head node; + void *virt_base; + dma_addr_t device_base; + unsigned long pfn_base; + int size; + spinlock_t spinlock; + unsigned long *bitmap; + bool use_dev_dma_pfn_offset; }; -static inline struct dma_coherent_mem *dev_get_coherent_memory(struct device *dev) -{ - if (dev && dev->dma_mem) - return dev->dma_mem; - return NULL; -} - static inline dma_addr_t dma_get_device_base(struct device *dev, struct dma_coherent_mem * mem) { @@ -61,6 +55,7 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr, dma_mem->pfn_base = PFN_DOWN(phys_addr); dma_mem->size = pages; dma_mem->use_dev_dma_pfn_offset = use_dma_pfn_offset; + INIT_LIST_HEAD(&dma_mem->node); spin_lock_init(&dma_mem->spinlock); return dma_mem; @@ -90,10 +85,8 @@ static int dma_assign_coherent_memory(struct device *dev, if (!dev) return -ENODEV; - if (dev->dma_mem) - return -EBUSY; + list_add_tail(&mem->node, &dev->dma_mems); - dev->dma_mem = mem; return 0; } @@ -118,23 +111,28 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size) { struct dma_coherent_mem *mem; - int ret; + int retval; mem = dma_init_coherent_memory(phys_addr, device_addr, size, false); if (IS_ERR(mem)) return PTR_ERR(mem); - ret = dma_assign_coherent_memory(dev, mem); - if (ret) + retval = dma_assign_coherent_memory(dev, mem); + if (retval) _dma_release_coherent_memory(mem); - return ret; + return retval; } void dma_release_coherent_memory(struct device *dev) { - if (dev) { - _dma_release_coherent_memory(dev->dma_mem); - dev->dma_mem = NULL; + struct dma_coherent_mem *mem_tmp, *q; + + if (!dev) + return; + + list_for_each_entry_safe(mem_tmp, q, &dev->dma_mems, node) { + list_del_init(&mem_tmp->node); + _dma_release_coherent_memory(mem_tmp); } } @@ -187,12 +185,17 @@ static void *__dma_alloc_from_coherent(struct device *dev, int dma_alloc_from_dev_coherent(struct device *dev, ssize_t size, dma_addr_t *dma_handle, void **ret) { - struct dma_coherent_mem *mem = dev_get_coherent_memory(dev); + struct dma_coherent_mem *mem_tmp; - if (!mem) + if (list_empty(&dev->dma_mems)) return 0; - *ret = __dma_alloc_from_coherent(dev, mem, size, dma_handle); + list_for_each_entry(mem_tmp, &dev->dma_mems, node) { + *ret = __dma_alloc_from_coherent(dev, mem_tmp, size, dma_handle); + if (*ret) + break; + } + return 1; } @@ -226,9 +229,16 @@ static int __dma_release_from_coherent(struct dma_coherent_mem *mem, */ int dma_release_from_dev_coherent(struct device *dev, int order, void *vaddr) { - struct dma_coherent_mem *mem = dev_get_coherent_memory(dev); + struct dma_coherent_mem *mem_tmp; + int retval = 0; - return __dma_release_from_coherent(mem, order, vaddr); + list_for_each_entry(mem_tmp, &dev->dma_mems, node) { + retval = __dma_release_from_coherent(mem_tmp, order, vaddr); + if (retval == 1) + break; + } + + return retval; } static int __dma_mmap_from_coherent(struct dma_coherent_mem *mem, @@ -271,9 +281,16 @@ static int __dma_mmap_from_coherent(struct dma_coherent_mem *mem, int dma_mmap_from_dev_coherent(struct device *dev, struct vm_area_struct *vma, void *vaddr, size_t size, int *ret) { - struct dma_coherent_mem *mem = dev_get_coherent_memory(dev); + struct dma_coherent_mem *mem_tmp; + int retval = 0; - return __dma_mmap_from_coherent(mem, vma, vaddr, size, ret); + list_for_each_entry(mem_tmp, &dev->dma_mems, node) { + retval = __dma_mmap_from_coherent(mem_tmp, vma, vaddr, size, ret); + if (retval == 1) + break; + } + + return retval; } #ifdef CONFIG_DMA_GLOBAL_POOL @@ -351,8 +368,17 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) static void rmem_dma_device_release(struct reserved_mem *rmem, struct device *dev) { - if (dev) - dev->dma_mem = NULL; + struct dma_coherent_mem *mem_tmp, *q; + + if (!dev) + return; + + list_for_each_entry_safe(mem_tmp, q, &dev->dma_mems, node) { + if (mem_tmp == rmem->priv) { + list_del_init(&mem_tmp->node); + break; + } + } } static const struct reserved_mem_ops rmem_dma_ops = { From patchwork Mon Mar 11 09:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Yen X-Patchwork-Id: 13588469 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A677E2BAFC for ; Mon, 11 Mar 2024 09:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710150605; cv=none; b=Dz1TLZOaf0jwclaKxTNWmAG0whBMkNsyJ+wr5KPDn+1ecEJi9T5pFda/RYp2nJ8mIL3HhYYM59jrzWmsjzbWEFbB2nArhSBwgThnMwh00xlZgAIdTJCTSn97YQaEU0Fe4I5fSqvbikXzrGw76j3sC0ibvrwRfqchu7+yeOajUBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710150605; c=relaxed/simple; bh=uvJ2hakYbHneCq8YNG7tuA44/YBDsJTeR/dxao+/8HQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R/GIgRuMaiysuKI/u7KYCJCKzccloxT6aLWCwCyRV8m5cSINnJBH8Ko/rdyybsg/Xy7/RPJmwlpKHZNsCtaMzI2yoe5PxuxSvT/dblFqP1NSYNJh0EtKCyAdAJfD4OAtdohKvr/I/cImnjrjePrTeBv3eC6y18kWWdSPDVDWKyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--howardyen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jdwn2ad8; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--howardyen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jdwn2ad8" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5cec8bc5c66so2940633a12.1 for ; Mon, 11 Mar 2024 02:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710150603; x=1710755403; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=U9nKgRIKf+zajKM49T+JUxDbdLW2EfnvvMithLFK/Yc=; b=Jdwn2ad8Yjvze3A/IsjvHJzhvSbO1gi9QO23jsfDhj2r9A+5kvu3/nu7UlL+mMgNRr o9aagpGNLo0caS1btUv5dxPFRAwhK3etIZPjHQZucQRvtmdJxRp7rGN8JwmttVmvJdvP iAVlxg5z1fMOEnBOsIXBau2LHW7FmpBbZeh2VDZywnr2AZVqWe7qFKybaeWy9l2RklQB BjPRHVExc3+YhznWIJyIosgOsLSa8gi583oo24vSp6xaEoJ5uNB/y27N1yAKNVSUoK/r CUbKNBrKcRLBd+oUVul8GFhk+PvCzDiY8WkwXr9kXq4SEDJbhypRgykOVMu3UU3hQQ+g IkzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710150603; x=1710755403; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U9nKgRIKf+zajKM49T+JUxDbdLW2EfnvvMithLFK/Yc=; b=fzqSWGvggLNBMOu7Bh1csRTVX2rIozPjLQygt9sK07RMQth5ENtbX+IEsY0fGL/tz5 jWKNLG34TeH9MhRCrv2e24f6cuAZlEK6JGchg9dH6TSG4+OacBMm6CG2YKeottX/Xw7I k+RmMzUCUUBPpKbXF1jXWnNn/VCu9O7mvTs/6u7y3JmA6d1IKVtSHq5KYTafjzlVc+CE s/GVWsI6LsoUddEdYXw1T0/+GiOBC1I6u3UPdHl0HE6rFUreUKt+aTR6bmu3M4hvcgAG 8jiR0MXFdoUqc/zfLtrO2ofyECbBgCIZijHhjUcEegxYMt1tvqp8gSx80bC8/Fb7hQ3U 9EEQ== X-Forwarded-Encrypted: i=1; AJvYcCXoQrifiAc941Xb+HUSZZPzCAow4LFa8AFKyA+2Ualu1cMC/q7dA3NSnwEEh7bbY0RALO3wJgdNK1lxsbyU5WJbQIOWrMBOwPnu X-Gm-Message-State: AOJu0Yw7XzE6Uu7xdjIdIJ4LEibuySoWzvrhnQbnkmT25kSx5cc3jie3 i4InWBbLmOc6Wv1G9KsJ9Qud0eKRiGo6xhFO2ZjB+WtJ42qjicZdimdZk6M03lzVbz79Opwx1UN CBSUVHAzAhagwoA== X-Google-Smtp-Source: AGHT+IE5C8YFsWfQeFn6ZmMrCYM8EsZdK0R7B2x7aijsSo9T46qxw3LGysRAMLa17HQzOWxQTbFW0fvfbLQGTOw= X-Received: from howardyen2.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:16f7]) (user=howardyen job=sendgmr) by 2002:a63:de0b:0:b0:5dc:aa2a:7790 with SMTP id f11-20020a63de0b000000b005dcaa2a7790mr17226pgg.2.1710150602720; Mon, 11 Mar 2024 02:50:02 -0700 (PDT) Date: Mon, 11 Mar 2024 09:49:47 +0000 In-Reply-To: <20240311094947.3738200-1-howardyen@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240311094947.3738200-1-howardyen@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240311094947.3738200-3-howardyen@google.com> Subject: [PATCH v5 2/2] usb: host: xhci-plat: add support for multi memory regions From: Howard Yen To: gregkh@linuxfoundation.org, rafael@kernel.org, mathias.nyman@intel.com, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, andriy.shevchenko@linux.intel.com, petr.tesarik.ext@huawei.com, broonie@kernel.org, james@equiv.tech, james.clark@arm.com, masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, iommu@lists.linux.dev, Howard Yen The reason why it needs multiple regions is that in my system there is an always-on subsystem which includes a small size memory, and several functions need to run and occupy the memory from the small memory if they need to run on the always-on subsystem. These functions must allocate the memory from the small memory region, so that they can get benefit from the always-on subsystem. So the small memory is split for multiple functions which are satisfied with their generic use cases. But in specific use cases, like USB3 devices which support the stream trasnsfer or multiple devices connect to the host, they required more memory than their pre-allocated memory region, so I tried to propose this patch to give it the ability to get the memory from the other larger memory to solve the issue. Signed-off-by: Howard Yen --- drivers/usb/host/xhci-plat.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 3d071b875308..7892d3eb26d2 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -149,7 +150,7 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s struct xhci_hcd *xhci; struct resource *res; struct usb_hcd *hcd, *usb3_hcd; - int ret; + int i, count, ret; int irq; struct xhci_plat_priv *priv = NULL; bool of_match; @@ -194,6 +195,19 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s xhci->allow_single_roothub = 1; + count = of_property_count_u32_elems(sysdev->of_node, "memory-region"); + + for (i = 0; i < count; i++) { + ret = of_reserved_mem_device_init_by_idx(sysdev, sysdev->of_node, i); + if (ret) { + dev_err(sysdev, "Could not get reserved memory\n"); + if (i > 0) + of_reserved_mem_device_release(sysdev); + + return ret; + } + } + /* * Not all platforms have clks so it is not an error if the * clock do not exist. @@ -431,6 +445,9 @@ void xhci_plat_remove(struct platform_device *dev) clk_disable_unprepare(clk); clk_disable_unprepare(reg_clk); reset_control_assert(xhci->reset); + + of_reserved_mem_device_release(hcd->self.sysdev); + usb_put_hcd(hcd); pm_runtime_disable(&dev->dev);