Re: howto provide io memory to PCI card

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




  Yes, thank you. pci_alloc_consistent seems to be what I need.

Rolf Eike Beer wrote:
Charles Brown wrote:
Grant,

    Early on I was using the altpciechdma driver as reference, but the
hardware engineer doesn't want me controlling the DMA on the card.  So,
we're just using memcpy_toio/fromio.

    That design also has the card providing host->board IO memory using
BAR0 and board->host using BAR2, but the HW engineer only wants to
provide host->board memory in BAR0, and me to provide the memory for
board->host - by allocating appropriate memory and handing back a
physical address. He has BAR2 set to 0.

   At this point, my best reference has been discarded, and I'm looking
for another. So, I'll track down the two you mention.  In the
meanintime, my code snippets are below - I've left out all my debug
printk's and error checking cruft.  The iomstart is an address
calculated from /proc/iomem, hence my mis-calling it "I/O memory".

   Thank you for spending some time with me on this.

--CB

/** start address for iomem block to allocate for read space */
unsigned long iomstart = 0, iomlength = 0;
module_param(iomstart,ulong,0);
module_param(iomlength,ulong,0);

...snip...

void alt_onInit(void)
{
   int i, status = 0;
   struct resource * resource = NULL;

   /* request IO memory for incoming data */
   resource = request_mem_region(iomstart, iomlength, DEVNAME);

Ehm, no, this functions is to request a memory range for something supplied from a hardware device, not you requesting RAM to pass to the device.

I would have done it like this:

void __iomem *mem;
void *outmem;
dma_addr_t outmem_phys;

// enable device (managed mode)
pcim_enable_device(pdev);
// claim BARs
pci_request_regions(pdev, DRIVER_NAME);
// map BAR0, full size
mem = pcim_iomap(pdev, 0, 0);
// get memory that is usable by DMA
outmem = pci_alloc_consistent(pdev, PAGE_SIZE, &outmem_phys);
// tell board about it
memcpy_toio(dest + 4, &outmem_phys, sizeof(outmem_phys));

Greetings,

Eike

-
This message is intended only for the addressee and may contain information that is company confidential or privileged. Any technical data in this message may be exported only in accordance with the U.S. International Traffic in Arms Regulations (22 CFR Parts 120-130) or the Export Administration Regulations (15 CFR Parts 730-774). Unauthorized use is strictly prohibited and may be unlawful. If you are not the intended recipient, or the person responsible for delivering to the intended recipient, you should not read, copy, disclose or otherwise use this message. If you have received this email in error, please delete it, and advise the sender immediately. - --
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux