From owner-freebsd-drivers@FreeBSD.ORG Mon Apr 10 15:31:54 2006 Return-Path: <owner-freebsd-drivers@FreeBSD.ORG> X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AD37116A401 for <freebsd-drivers@freebsd.org>; Mon, 10 Apr 2006 15:31:54 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id B88F943D6E for <freebsd-drivers@freebsd.org>; Mon, 10 Apr 2006 15:31:45 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.4/8.13.4) with ESMTP id k3AFUDUL041739; Mon, 10 Apr 2006 09:30:13 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 10 Apr 2006 09:30:15 -0600 (MDT) Message-Id: <20060410.093015.34601940.imp@bsdimp.com> To: nickolas@atlas.ua From: "M. Warner Losh" <imp@bsdimp.com> In-Reply-To: <637898557.20060410154542@atlas.ua> References: <637898557.20060410154542@atlas.ua> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-drivers@freebsd.org Subject: Re: Context switching X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD <freebsd-drivers.freebsd.org> List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-drivers>, <mailto:freebsd-drivers-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/freebsd-drivers> List-Post: <mailto:freebsd-drivers@freebsd.org> List-Help: <mailto:freebsd-drivers-request@freebsd.org?subject=help> List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-drivers>, <mailto:freebsd-drivers-request@freebsd.org?subject=subscribe> X-List-Received-Date: Mon, 10 Apr 2006 15:31:54 -0000 In message: <637898557.20060410154542@atlas.ua> Nickolas <nickolas@atlas.ua> writes: : Hello All! : : I'm porting a CPI card driver from linux to FreeBSD. : Some initialization routines require much time (~1-2 seconds). : Initialization of hardware should be done during opening device : special file. So, I need to switch thread context. : : I'm doing it in such way: : : mi_switch(SW_VOL, choosethread()); : : Main trouble: system panic after program exit. : : dmesg output: : -------------------------- : Fatal trap 12: page fault while in user mode : fault virtual address = 0xbfbfe5bc : fault code = user write, protection violation : instruction pointer = 0x1f:0x8074604 : stack pointer = 0x2f:0xbfbfe5c0 : frame pointer = 0x2f:0xbfbfe5f8 : code segment = base 0xc090f8c0, limit 0x0, type 0x13 : = DPL 0, pres 1, def32 1, gran 1 : processor eflags = interrupt enabled, resume, IOPL = 0 : current process = 472 (bash) : trap number = 12 : panic: page fault : -------------------------- : : Please, tell how correct context switching should be implemented? Create a thread on attach. Have it msleep. Use wakeup from open and have open msleep. The thread then runs, does its init and wakes up the open thread to continue. Of course, you could likely do all that in the open thread... Warner