Re: constants in kernel module (SUMMARY)

Gerard Roudier (groudier@club-internet.fr)
Sun, 19 Apr 1998 19:05:02 +0200 (MET DST)


On Sun, 19 Apr 1998, Marc SCHAEFER wrote:

> The original question was:
> > in a device driver, I have declared:
> > static const unsigned char buffer[] = { 'a', 'b', 'c', 'd' };
> >
> > If I pass virt_to_bus(buffer) to a PCI DMA, I get garbage. If
> > I kmalloc() and memcpy() the const buffer to that kmalloc()ed
> > memory, and pass do virt_to_bus(kmalloced_memory) to the PCI
> > DMA, it works like a charm (ix86 architecture).
>
> Non immediately pertaining answers, but anyway interesting
> information:
> - for ISA DMA, the memory MUST be located below 16MB (GPF_DMA to
> kmalloc()). Constants might not be located there. This does not
> look to be a problem with the PCI bus.
>
> PCI information:
> - Some PCI devices will need 4 or 8 bytes or even stronger alignment
> constraints.
> - The constant data could span two different non contiguous pages
> and thus only the beginning would be seen (well, I see nothing really).
>
> Unresolved points:
> - groudier@club-internet.fr say that virt_to_bus() is not needed
> on driver space, which is allocated through vmalloc(). Maybe
> this is true on x86 because there virt_to_bus(x) == (x), but
> I doubt this is true in the general case.

My reply was unclear, and you could understand it this way.
Below is the reply I sent you about this misundertanding.

On Sun, 19 Apr 1998, Marc SCHAEFER wrote:

> On Thu, 16 Apr 1998, Gerard Roudier wrote:
> > If your driver is loaded as a module then I would think your buffer
> > space is allocated using vmalloc().
> > Since I never used vir_to_bus() for vmallocced memory and I never
> > got problems using such an address translation, this could well be
> > the cause of the problem.
>
> what did you do with that allocated memory ? did you DMA from/to it?
>
> Unresolved points:
> - groudier@club-internet.fr say that virt_to_bus() is not needed
> on driver space, which is allocated through vmalloc(). Maybe
> this is true on x86 because there virt_to_bus(x) == (x), but
> I doubt this is true in the general case.

Indeed, my reply is not clear.
virt_to_bus() does not work for vmalloced memory and vmalloced memory
addresses donnot match PCI BUS addresses.

virt_to_bus() only works for primary kernel memory addresses that are
just PHYSICAL ADDRESS + A FIXED OFFSET (0xc000000 by default).

Modules are loaded in the kernel at different virtual addresses since,
IMO, they have segments generally larger that 1 PAGE and vmalloc()
remaps physical pages into a virtually contiguous area.

If we want to DMA from PCI into a vmalloced memory area, we must first
fix virt_to_bus(). Linus, perhaps, missed our postings and this is very
understandable ..., but my guess could be that he would recommend not
to use vmalloced memory for PCI DMA, since this would make things complex
and we can live without this feature.

Regards,
Gerard.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu