Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Aug 2004 17:53:14 +0900
From:      takawata@jp.freebsd.org
To:        Iasen Kostov <tbyte@OTEL.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: How can I fake a device ?
Message-ID:  <200408200853.RAA05110@axe-inc.co.jp>
In-Reply-To: Your message of "Fri, 20 Aug 2004 10:03:58 %2B0300." <4125A25E.4050602@OTEL.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In message <4125A25E.4050602@OTEL.net>, Iasen Kostov wrote:

>>>   Hi,
>>>I want to know is there a way to call *_probe (for device driver) with 
>>>fake (PCI) device that does not exists in the system ?
>>>First of all a cant find how "struct device" is declared (i've searched 
>>>even the compile/ dir) and second I think that I'll need to intercept 
>>>pci_get_vendor and pci_get_device funcs with my own which should detect 
>>>the fake device and thus will return vandor/device that I need to fake. 
>>>I realy don't need anything else except _probe ...
>>>    
>>>
>>
>>I have never tried such but grimpsed the PCI framework, 
>>I propose the following, though I don't imagine why you want 
>>to do so:
>>
>>Your driver have to contain DEVICE_IDENTIFY method 
>>that calls device_add_child to allocate device_t object.
>>Then you allocate 'struct pci_devinfo' and initialize 
>>pci_devinfo as you like. And you have to make your 
>>driver as a module. Then a device object will show up on 
>>the device tree on your system.
>>
>>You may want to have a look at pci_add_children@/sys/dev/pci/pci.c 
>>
>>  
>>
>I think I was not clear .. .sorry. I ment to lie the driver that some 
>device (that is not realy plugged in the machine) exists. Doing so I can 
>check if drivers _probe() func returns "OK"
>or not and by checking every device from /usr/share/misc/pci_vendors I 
>could build device<->driver_file database.

Hmm, do you want to implement docking station or something?
This is a part of my interest.

>I've patched a bit /sys/dev/pci/pci.c like this:
>
>typedef uintptr_t *pci_fake_read_ivars_t(pcicfgregs *cfg);
>static pci_fake_read_ivars_t *pci_fake_read_ivars = NULL;
>
>int
>pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
>{
>        struct pci_devinfo *dinfo;
>        pcicfgregs *cfg = NULL;
>
>        if(pci_fake_read_ivars && !strcmp("fake0", dev->nameunit)) {
>            (*pci_fake_read_ivars)(cfg);
>        } else {
>            dinfo = device_get_ivars(child);
>            cfg = &dinfo->cfg;
>        }
>
>And when I load my module it will set pci_fake_read_ivars and will start 
>to test drivers probe sending devices with nameunit set to "fake0" thus 
>telling pci_read_ivar() to fake the return values by calling 
>pci_fake_read_ivars() callback ... I think this is very messy ... I hope 
>that it will work this way :)

pci_read_ivar itself will not access real hardware: cache its value and 
simply use hardware register index as ivar index.
So it is enough to initialize
struct pci_devinfo then call device_set_ivar. Rather, there may be problem
 when pci_cfg_save()@sys/dev/pci/pci.c is called.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200408200853.RAA05110>