mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Denis Orlov <denorl2009@gmail.com>
To: barebox@lists.infradead.org
Cc: Denis Orlov <denorl2009@gmail.com>
Subject: [PATCH 16/16] ata: ahci: allocate memory in one call in ahci_init_port()
Date: Wed,  4 May 2022 12:25:53 +0300	[thread overview]
Message-ID: <20220504092553.27961-16-denorl2009@gmail.com> (raw)
In-Reply-To: <20220504092553.27961-1-denorl2009@gmail.com>

Memory allocated with dma_alloc_coherent() is aligned by page size.
Calling it multiple times leads to unnecessary fragmentation and
overhead considering that we are actually able to allocate all the
memory that we need at once by issuing only one call.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 drivers/ata/ahci.c | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 24098ada08..f707efb50f 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -273,6 +273,8 @@ static int ahci_write(struct ata_port *ata, const void *buf, sector_t block,
 static int ahci_init_port(struct ahci_port *ahci_port)
 {
 	u32 val, cmd;
+	void *mem;
+	dma_addr_t mem_dma;
 	int ret;
 
 	/* make sure port is not active */
@@ -290,16 +292,17 @@ static int ahci_init_port(struct ahci_port *ahci_port)
 		mdelay(500);
 	}
 
+	mem = dma_alloc_coherent(AHCI_PORT_PRIV_DMA_SZ, &mem_dma);
+	if (!mem) {
+		return -ENOMEM;
+	}
+
 	/*
 	 * First item in chunk of DMA memory: 32-slot command list,
 	 * 32 bytes each in size
 	 */
-	ahci_port->cmd_slot = dma_alloc_coherent(AHCI_CMD_LIST_SZ,
-						  &ahci_port->cmd_slot_dma);
-	if (!ahci_port->cmd_slot) {
-		ret = -ENOMEM;
-		goto err_alloc;
-	}
+	ahci_port->cmd_slot = mem;
+	ahci_port->cmd_slot_dma = mem_dma;
 
 	ahci_port_debug(ahci_port, "cmd_slot = 0x%p (0x%pa)\n",
 			ahci_port->cmd_slot, ahci_port->cmd_slot_dma);
@@ -307,22 +310,15 @@ static int ahci_init_port(struct ahci_port *ahci_port)
 	/*
 	 * Second item: Received-FIS area
 	 */
-	ahci_port->rx_fis = dma_alloc_coherent(AHCI_RX_FIS_SZ, &ahci_port->rx_fis_dma);
-	if (!ahci_port->rx_fis) {
-		ret = -ENOMEM;
-		goto err_alloc1;
-	}
+	ahci_port->rx_fis = mem + AHCI_CMD_SLOT_SZ;
+	ahci_port->rx_fis_dma = mem_dma + AHCI_CMD_SLOT_SZ;
 
 	/*
 	 * Third item: data area for storing a single command
 	 * and its scatter-gather table
 	 */
-	ahci_port->cmd_tbl = dma_alloc_coherent(AHCI_CMD_TBL_SZ,
-						 &ahci_port->cmd_tbl_dma);
-	if (!ahci_port->cmd_tbl) {
-		ret = -ENOMEM;
-		goto err_alloc2;
-	}
+	ahci_port->cmd_tbl = mem + AHCI_CMD_SLOT_SZ + AHCI_RX_FIS_SZ;
+	ahci_port->cmd_tbl_dma = mem_dma + AHCI_CMD_SLOT_SZ + AHCI_RX_FIS_SZ;
 
 	ahci_port_debug(ahci_port, "cmd_tbl = 0x%p (0x%pa)\n",
 			ahci_port->cmd_tbl, ahci_port->cmd_tbl_dma);
@@ -418,15 +414,7 @@ static int ahci_init_port(struct ahci_port *ahci_port)
 	ret = -ENODEV;
 
 err_init:
-	dma_free_coherent(ahci_port->cmd_tbl, ahci_port->cmd_tbl_dma,
-			  AHCI_CMD_TBL_SZ);
-err_alloc2:
-	dma_free_coherent(ahci_port->rx_fis, ahci_port->rx_fis_dma,
-			  AHCI_RX_FIS_SZ);
-err_alloc1:
-	dma_free_coherent(ahci_port->cmd_slot, ahci_port->cmd_slot_dma,
-			  AHCI_CMD_LIST_SZ);
-err_alloc:
+	dma_free_coherent(mem, mem_dma, AHCI_PORT_PRIV_DMA_SZ);
 	return ret;
 }
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2022-05-04  9:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04  9:25 [PATCH 01/16] ata: ahci: use abstract read/write functions uniformly Denis Orlov
2022-05-04  9:25 ` [PATCH 02/16] ata: ahci: replace magic numbers with named constants Denis Orlov
2022-05-04  9:25 ` [PATCH 03/16] ata: ahci: fix missing whitespace in ahci_add_host() Denis Orlov
2022-05-04  9:25 ` [PATCH 04/16] ata: ahci: simplify fis structure creation Denis Orlov
2022-05-04  9:25 ` [PATCH 05/16] ata: ahci: do not ignore dma handles Denis Orlov
2022-05-04  9:25 ` [PATCH 06/16] ata: ahci: adjust debug messages in ahci_init_port() Denis Orlov
2022-05-04  9:25 ` [PATCH 07/16] ata: ahci: correct named constants values and names Denis Orlov
2022-05-04  9:25 ` [PATCH 08/16] ata: ahci: properly fill scatter/gather table Denis Orlov
2022-05-04  9:25 ` [PATCH 09/16] ata: ahci: use named constants for capabilities bits Denis Orlov
2022-05-04  9:25 ` [PATCH 10/16] ata: ahci: map buffers properly Denis Orlov
2022-05-04  9:25 ` [PATCH 11/16] ata: ahci: use 64-bit addressing if available Denis Orlov
2022-05-04  9:25 ` [PATCH 12/16] ata: ahci: make rx_fis field in ahci_port of type void* Denis Orlov
2022-05-04  9:25 ` [PATCH 13/16] ata: ahci: add missing capability in ahci_print_info() Denis Orlov
2022-05-04  9:25 ` [PATCH 14/16] ata: ahci: remove redundant cast in ahci_io() Denis Orlov
2022-05-04  9:25 ` [PATCH 15/16] ata: ahci: register only implemented ports Denis Orlov
2022-05-04  9:25 ` Denis Orlov [this message]
2022-05-05  7:48 ` [PATCH 01/16] ata: ahci: use abstract read/write functions uniformly Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504092553.27961-16-denorl2009@gmail.com \
    --to=denorl2009@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox