Re: pci_alloc_resource is broken

From: John Baldwin <jhb_at_freebsd.org>
Date: Mon, 30 Mar 2009 12:14:32 -0400
On Monday 30 March 2009 11:53:02 am Barney Cordoba wrote:
> > This was actually on purpose to prevent multiple
> > allocations of a resource.  
> > Multiple allocations actually leak kernel memory since the
> > resource only 
> > keeps track of the current mapping.  My question is why are
> > you having one 
> > device allocate resources of another device?  If you have
> > two functions of a 
> > multi-function PCI adapter that you want one logical driver
> > for, then have 
> > each function's driver allocate its own resources and
> > store the 'struct 
> > resource *' in a "global" softc.  You can
> > then use whichever resource you 
> > need for bus_read/write when you do bit-banging.
> > 
> > -- 
> > John Baldwin
> 
> We're remapping in another driver because in the commercial world,
> we don't always have access to kernel source, and there is a strong
> desire to separate the NIC driver from the secondary function so 
> customers can get patches for the OS without having to worry about
> incompatibility with the secondary modules.
> 
> I can add a function to the NIC driver also, but the goal is to be
> able to distribute a module that doesn't require modification to the
> stock driver for the system.

In FreeBSD you do always have access to the source. :)  (And fwiw, I have 
worked on proprietary FreeBSD drivers in the past including a driver for a 
multi-function card that actually managed two functions via one logical 
driver.)

However, I am curious that you are able to make this work on "commercial" 
operating systems as well.  On OS X only the IOService child of a PCI node 
can map the BARs of that node.  Well, you can actually walk up to the parent 
PCI bus, find your sibling IOService node and get its BARs that way which 
does work.  In Windows I'm not sure how you would make this work as when you 
attach to a FDO you get callbacks for each of your resources for tha tnode in 
BAR order.  AFAIK, there isn't a good way to discover or use the resources of 
another device in WDM, at least not at the time of Windows XP.

-- 
John Baldwin
Received on Mon Mar 30 2009 - 14:14:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:45 UTC