Re: howto provide io memory to PCI card

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

 



On Thu, Apr 29, 2010 at 09:55:05AM -0400, 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.

You want to use dma_alloc_coherent() since it's going to be a
persistent mapping and will be re-used, albeit only for PCI->host
transfers.

>   At this point, my best reference has been discarded, and I'm looking  
> for another.

I don't know of any other devices that have exactly this behavior.
It sounds like a data acquisition device and you might find others.

> 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.

Sorry - I've not been available lately. I see someone else
already replied (which I haven't read yet). I'll reply again
if I have anything else to add tomorrow (Sunday).

cheers,
grant

>
> --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);
>
> ...snip...
>
> int
> alt_probe(struct pci_dev *dev, const struct pci_device_id *id)
> {
> ...snip...
>
>   /* get BAR0 addresses */
>   start = pci_resource_start(board->dev, 0);
>   end = pci_resource_end(board->dev, 0);
>   size = (end - start);
>
>   /* write address back, so board can use it in address translation */
>   dest = (unsigned char *)ioremap( start, size );
>   memcpy_toio( &dest[4], &board->iomstart, sizeof(board->iomstart) );
>   memcpy_toio( &dest[4+sizeof(board->iomstart)], &board->iomlength,  
> sizeof(board->iomlength) );
>   memcpy_toio( &dest[0], "RDY\0", 4 );
>   iounmap( dest );
>
> ...snip...
>
> /* Read data from the altera board. */
> void alt_read( size_t boardno )
> {
> ...snip...
>   /* get board addresses */
>   start = board->iomstart;
>   size = board->iomlength;
>
>   /* read data board has written into host IO memory */
>   src = (unsigned char *)ioremap( start, size );
>   memcpy_fromio( dest, src, 256 );
>   iounmap( src );
>
>
> Grant Grundler wrote:
>> On Tue, Apr 27, 2010 at 04:48:40PM -0400, Charles Brown wrote:
>>  > All,
>>  >
>>  >    I'm trying to write a device driver under ubuntu for a PCI card, 
>> and  > exchange information with the card.
>>  >
>>  >    The hardware engineer has configured the card to support BAR0 for 
>>  > data to the card, and linux allocates memory at kernel boot and I am 
>>  > able to write data from the driver to the card.
>>  >
>>  >    For data coming from the card to the driver, the hardware 
>> engineer  > expects the driver to allocate IO memory when the driver 
>> loads, and to  > provide the physical address of that memory to the 
>> card - which the card  > will use with its address translation 
>> register, to write data directly  > into the provided I/O memory.
>>
>> I think you are confused here. "I/O Memory" is on the card. Your engineer
>> is telling you he wants the card to transfer data to *host* memory.
>> The card needs a "PCI Bus Address" (aka "physical address") to access
>> that memory and Documentation/DMA-API.txt will explain that to you.
>>
>>  >   Using information from LDD3 I've been able to allocate IO memory, 
>> but  > I can't find any PCI/kernel functions that allow me to tell the 
>> kernel  > about this memory for the PCI card, and there's no way to 
>> tell the card  > about this memory, except through writing the physical 
>> address back into  > the IO memory associated to BAR0.
>>  >
>>  >   How do I make this allocated memory available to the card?
>>
>> See how other drivers use interfaces described in Documentation/DMA-API.txt.
>> e.g. drivers/net/bnx2 or drivers/scsi/mpt2sas
>>
>> It would be helpful if you could post the code some place.  Assuming you
>> can't and this driver will be released under GPL, just copy code from a
>> similar driver.
>>
>> hth,
>> grant
>> --
>> 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
>>
>
> -
> 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