From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Tue, 9 Aug 2011 17:37:29 -0500 Subject: [U-Boot] [PATCH] NAND: Allow per-buffer allocation In-Reply-To: <1312926890-21361-1-git-send-email-marek.vasut@gmail.com> References: <1312926890-21361-1-git-send-email-marek.vasut@gmail.com> Message-ID: <4E41B6A9.1030701@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 08/09/2011 04:54 PM, Marek Vasut wrote: > Don't allocate NAND buffers as one block, but allocate them separately. This > allows systems where DMA to buffers happen to allocate these buffers properly > aligned. > > Signed-off-by: Marek Vasut That second sentence is hard to parse -- I think you mean something like, "This accommodates drivers which DMA to the buffers and have alignment constraints." Will a similar change be needed in Linux? > int nand_scan_tail(struct mtd_info *mtd) > { > - int i; > + int i, bufsize; > + uint8_t *buf; > struct nand_chip *chip = mtd->priv; > > - if (!(chip->options & NAND_OWN_BUFFERS)) > - chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL); > - if (!chip->buffers) > + if (!(chip->options & NAND_OWN_BUFFERS)) { > + chip->buffers = malloc(sizeof(struct nand_buffers)); > + if (!chip->buffers) > + return -ENOMEM; Why does the struct itself need to be dynamically allocated? > + > + bufsize = NAND_MAX_PAGESIZE + (3 * NAND_MAX_OOBSIZE); > + buf = malloc(bufsize); > + > + chip->buffers->buffer = (struct nand_buffers *)buf; > + chip->buffers->ecccalc = buf; > + chip->buffers->ecccode = buf + NAND_MAX_OOBSIZE; > + chip->buffers->databuf = buf + (2 * NAND_MAX_OOBSIZE); > + } > + > + if (!chip->buffers->buffer) > return -ENOMEM; What does "buffer" mean now? What would a driver that supplies its own completely separate ecccalc/ecccode/databuf buffers put in "buffer"? -Scott