From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [RESEND] [PATCH 1/2] OMAP1: allow reserving memory for camera
Date: Mon, 13 Dec 2010 16:29:47 +0000 [thread overview]
Message-ID: <20101213162947.GA11730@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <AANLkTimTVWVmVfppAWSosidqLmo6c+8rPhLg=oJAVoYH@mail.gmail.com>
On Mon, Dec 13, 2010 at 03:52:20PM +0000, Catalin Marinas wrote:
> On 10 December 2010 17:03, Russell King - ARM Linux
> <linux@arm.linux.org.uk> wrote:
> > On Fri, Dec 10, 2010 at 12:03:07PM +0100, Janusz Krzysztofik wrote:
> >> ?void __init omap1_camera_init(void *info)
> >> ?{
> >> ? ? ? struct platform_device *dev = &omap1_camera_device;
> >> + ? ? dma_addr_t paddr = omap1_camera_phys_mempool_base;
> >> + ? ? dma_addr_t size = omap1_camera_phys_mempool_size;
> >> ? ? ? int ret;
> >>
> >> ? ? ? dev->dev.platform_data = info;
> >>
> >> + ? ? if (paddr) {
> >> + ? ? ? ? ? ? if (dma_declare_coherent_memory(&dev->dev, paddr, paddr, size,
> >> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE))
> >
> > Although this works, you're ending up with SDRAM being mapped via
> > ioremap, which uses MT_DEVICE - so what is SDRAM ends up being
> > mapped as if it were a device.
>
> BTW, does the generic dma_declare_coherent_memory() does the correct
> thing in using ioremap()?
I argue it doesn't, as I said above. It means we map SDRAM as device
memory, and as I understand the way interconnects work, it's entirely
possible that this may not result in the SDRAM being accessible.
> Maybe some other function that takes a
> pgprot_t would be better (ioremap_page_range) and could pass something
> like pgprot_noncached (though ideally a pgprot_dmacoherent). Or just
> an architecturally-defined function.
This API was designed in the ARMv5 days when things were a lot simpler.
What we now have is rather messy though, and really needs sorting out
before we get too many users of it. (Arguably it should never have been
accepted in its current state.)
We have a rule that the returned value of ioremap() is not to be used
as a pointer which can be dereferenced by anything except driver code.
Yet this is exactly what dma_declare_coherent_memory() does:
struct dma_coherent_mem {
void *virt_base;
...
};
int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
dma_addr_t device_addr, size_t size, int flags)
{
void __iomem *mem_base = NULL;
mem_base = ioremap(bus_addr, size);
dev->dma_mem->virt_base = mem_base;
}
int dma_alloc_from_coherent(struct device *dev, ssize_t size,
dma_addr_t *dma_handle, void **ret)
{
*ret = mem->virt_base + (pageno << PAGE_SHIFT);
}
and drivers expect the returned value from dma_alloc_coherent() to be
dereferenceable.
Note that this also fails sparse checking. It will fail on any
architecture where the return value from ioremap() is not a virtual
address.
So, not only does this fail the kernel's own rules, but as we already know,
it fails the architecture's restrictions with multiple mappings of memory
when used with SDRAM, and it also maps main memory as a device. I wonder
how many more things this broken API needs to do wrong before it's current
implementation is consigned to the circular filing cabinet.
next prev parent reply other threads:[~2010-12-13 16:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <201012051929.07220.jkrzyszt@tis.icnet.pl>
2010-12-10 10:59 ` [RESEND] [PATCH 0/2] OMAP1: amsdelta: reserve memory for videobuf_contig Janusz Krzysztofik
2010-12-10 11:03 ` [RESEND] [PATCH 1/2] OMAP1: allow reserving memory for camera Janusz Krzysztofik
2010-12-10 17:03 ` Russell King - ARM Linux
2010-12-10 21:03 ` Janusz Krzysztofik
2011-06-08 21:53 ` Janusz Krzysztofik
2011-06-08 22:13 ` Russell King - ARM Linux
2011-06-08 22:44 ` Janusz Krzysztofik
2011-07-12 9:53 ` Janusz Krzysztofik
2010-12-13 15:52 ` Catalin Marinas
2010-12-13 16:29 ` Russell King - ARM Linux [this message]
2010-12-15 12:39 ` Catalin Marinas
2010-12-15 17:01 ` Russell King - ARM Linux
2010-12-19 11:46 ` Janusz Krzysztofik
2010-12-10 11:05 ` [PATCH 2/2] OMAP1: Amstrad Delta: reserve " Janusz Krzysztofik
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=20101213162947.GA11730@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).