From owner-freebsd-hackers Fri Dec 10 23: 5:40 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from mass.cdrom.com (castles536.castles.com [208.214.165.100]) by hub.freebsd.org (Postfix) with ESMTP id 9996414DC2 for ; Fri, 10 Dec 1999 23:05:32 -0800 (PST) (envelope-from msmith@mass.cdrom.com) Received: from mass.cdrom.com (localhost [127.0.0.1]) by mass.cdrom.com (8.9.3/8.9.3) with ESMTP id XAA00875; Fri, 10 Dec 1999 23:08:03 -0800 (PST) (envelope-from msmith@mass.cdrom.com) Message-Id: <199912110708.XAA00875@mass.cdrom.com> X-Mailer: exmh version 2.1.1 10/15/1999 To: Bob Kot Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Device driver - panics executing kvtop() when compiled as KLD module In-reply-to: Your message of "Fri, 10 Dec 1999 17:15:43 MST." <99121017414100.00289@atlas.tic.toc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 10 Dec 1999 23:08:02 -0800 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > I am in the process of writing a device driver for the Turtle Beach Multisound > Monterey soundcard. At the moment I am statically compiling my code into the > kernel and it is somewhat operational. I have added conditional compilation > code to also compile as a kld module. My problem is that when I kldload my > module the machine panics in a subfunction of my attach() function that makes > a call on kvtop() I drop into the debugger DDB and the instruction pointer is > in the middle of the kvtop() function. If I disable my attach function the > module will load and unload, but it is nonfunctional without the attach() > being executed. Statically compiled into the kernel kvtop() executes with no > problem. > > To be succinct can I use kvtop() in code that is a kld module? Yes, althought it's not the right way to do this. > If not, what is the alternative to accomplish the same result? You should be using the bus_space functionality to hide the mapping. > switch (kvtop(msd->dev->id_maddr)) { Er. You do understand that kvtop() attempts to return a physical address when given a kernel virtual address, right? The isa_device id_maddr field is a physical address, for which you want a mapping in kernel virtual space. Assuming you don't want to do this properly and use bus_space, you need to use pmap_mapdev(), or to take advantage of the fact that the ISA hole is already mapped into kernel virtual space. You can convert a physical address in the ISA hole to a virtual address in kernel space with: #include #include ... vaddr = (paddr - ISA_HOLE_START) + atdevbase; Note that this approach is somewhat frowned upon, and if you're working with -current it is very definitely the wrong way to do it, but for an expedient solution it'll do the job. -- \\ Give a man a fish, and you feed him for a day. \\ Mike Smith \\ Tell him he should learn how to fish himself, \\ msmith@freebsd.org \\ and he'll hate you for a lifetime. \\ msmith@cdrom.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message