From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 20 09:10:37 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AFCB116A4CE for ; Fri, 20 Aug 2004 09:10:37 +0000 (GMT) Received: from mail.otel.net (gw3.OTEL.net [212.36.8.151]) by mx1.FreeBSD.org (Postfix) with ESMTP id 357AD43D2F for ; Fri, 20 Aug 2004 09:10:37 +0000 (GMT) (envelope-from tbyte@OTEL.net) Received: from dragon.otel.net ([212.36.8.135]) by mail.otel.net with esmtp (Exim 4.30; FreeBSD) id 1By5Pv-0003Mt-BW; Fri, 20 Aug 2004 12:10:35 +0300 Message-ID: <4125C00A.4080205@OTEL.net> Date: Fri, 20 Aug 2004 12:10:34 +0300 From: Iasen Kostov User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.1) Gecko/20040728 X-Accept-Language: en-us, en MIME-Version: 1.0 To: takawata@jp.freebsd.org, freebsd-hackers@freebsd.org References: <200408200853.RAA05110@axe-inc.co.jp> In-Reply-To: <200408200853.RAA05110@axe-inc.co.jp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: How can I fake a device ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2004 09:10:37 -0000 takawata@jp.freebsd.org wrote: >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. > > > Don't know what you mean whit "docking station". I want to create framework for extracting info from every driver which device it can handle. Then create create conf for devd or kernel_driver_autoloader :) or something like that (e.g. windoze .inf database). >>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. > > Thank a lot this will realy simplify the work ! :) I won't need to patch sys/dev/pci/pci.c this way. Thanks .