<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 7, 2016 at 3:29 PM, Greg KH <span dir="ltr"><<a href="mailto:greg@kroah.com" target="_blank">greg@kroah.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Mar 07, 2016 at 03:21:44PM -0500, Kenneth Adam Miller wrote:<br>
><br>
><br>
> On Mon, Mar 7, 2016 at 3:17 PM, Greg KH <<a href="mailto:greg@kroah.com">greg@kroah.com</a>> wrote:<br>
><br>
> On Mon, Mar 07, 2016 at 03:00:50PM -0500, Kenneth Adam Miller wrote:<br>
> > I have a driver that manages three sets of identical data structures that<br>
> > differ only in address values. Currently, I pray that the device file to<br>
> which<br>
> > I have callbacks mapped for the driver gets called sequentially, because<br>
> there<br>
> > are pairs of mmap's that need to be made. I know that this isn't the most<br>
> ideal<br>
> > way to do it, so I'm searching for a better way rather than to swap out<br>
> the<br>
> > values on each method call. <br>
> ><br>
> > There are several things I am aware of but for each one I have questions:<br>
> > 1) there are kernel module parameters<br>
> > If I use kernel module parameters, I need to be able to insert the kernel<br>
> > module three times in order to have each one have a distinct set of<br>
> global<br>
> > memory and mapped callbacks to distinct files. Can that be done? Second,<br>
> I will<br>
> > need to compile the driver statically later. How can I pass those<br>
> parameters<br>
> > that would otherwise be on the command line in statically?<br>
><br>
> Never use kernel module parameters for a driver, nor for any other<br>
> kernel module you create. They are global and don't work for<br>
> device-specific issues.<br>
><br>
> > 2) I can compile the driver in three times with a compile time flag. This<br>
> is<br>
> > the simplest and easiest, but it requires some buildroot and makefile foo<br>
> that<br>
> > I think is a dirty hack.<br>
><br>
> It's also never accepted, don't do that.<br>
><br>
> > 3) I could have the init function create three separate files, since it<br>
> is on<br>
> > init that I discover what my values are. But then I have to also<br>
> associate<br>
> > identical functions that reference global variables in the kernel object.<br>
> > Duplicating the code would be worse that compiling the same code three<br>
> times<br>
> > with a kernel parameter, even though that would help me solve my distinct<br>
> > globals problem. So how could I parameterisze a char device with data<br>
> specific<br>
> > to the instance?<br>
><br>
> open() gives you the hook to do so, please just do that. There's a<br>
> whole kernel tree full of examples of how to do this, take a look at<br>
> existing code please.<br>
><br>
><br>
> After I had the idea in the second email, I think that using the kernel api to<br>
> distinguish which char device a callback maps to in order to utilize the<br>
> corresponding data is the best way.<br>
><br>
> If I could do something along the lines of retrieving the file name, as in a<br>
> char *,<br>
<br>
</div></div>There is no such "thing" in the kernel (think of symlinks, or different<br>
names for the same major:minor pair).<br>
<span class=""><br>
> from the file * that is passed in with the callback, or distinguish any<br>
> one of these:<br>
><br>
> static dev_t LSKSMM_dev;<br>
> static struct cdev LSKSMM_cdev;<br>
> static struct class *LSKSMM_class;<br>
> static struct device *LSKSMM_device;<br>
<br>
</span>Those are all different things, none of them get passed into open().<br>
<br>
I don't think you have thought this through very far, where is your<br>
source code to take a look at it?<br>
<span class=""><br>
> which are also created on module init, it would really make things convenient<br>
> and easy. I'm currently digging around in the kernel headers, but I think<br>
> probably somebody somewhere knows what I'm looking for. Some unique field that<br>
> I can retain on init that I can get back in my mmap/ioctl call to recognize<br>
> what data to use.<br>
<br>
</span>Again, it's all provided directly to you in your open() call, what's<br>
wrong with that?<br></blockquote><div><br></div><div>Currently, my kernel driver is opened twice and mmap'd twice by each process. I have three processes, but I have to initialize them on startup with a startup script. So they come up as daemons, racing, which is a problem. I know that on init I can create three entries in /dev/, distinguished by a number or something that makes the device unique. When a mmap call hits is when I need to know what specific file that the mmap corresponds to. I have to identify it associatively by name or by the identifiers that the kernel consumes for it's internal class and/or device entry. I don't know that I could do that with what I'm given in open, because while I'm sure that provides some information, it doesn't provide the the information when I need it. I don't have anything in my open callback except a printk. My mmap does all the work, and has to distinguish the right private item to use with what device file.</div><div><br></div><div>I don't know the layout of the structure or the api so well that I could do that off the top of my head.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
thanks,<br>
<br>
greg k-h<br>
</blockquote></div><br></div></div>