From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 25 18:55:56 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2E9BC1065670; Tue, 25 Jan 2011 18:55:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 00FCD8FC0C; Tue, 25 Jan 2011 18:55:56 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id AB7EC46B0C; Tue, 25 Jan 2011 13:55:55 -0500 (EST) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 6FD4F8A009; Tue, 25 Jan 2011 13:55:54 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org, philip-freebsd1@soeberg.net Date: Tue, 25 Jan 2011 13:55:53 -0500 User-Agent: KMail/1.13.5 (FreeBSD/7.4-CBSD-20110107; KDE/4.4.5; amd64; ; ) References: <4D3EE287.3010203@soeberg.net> In-Reply-To: <4D3EE287.3010203@soeberg.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201101251355.53944.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 25 Jan 2011 13:55:54 -0500 (EST) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-1.9 required=4.2 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: Warner Losh Subject: Re: pci_suspend/pci_resume of custom pcie board X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jan 2011 18:55:56 -0000 On Tuesday, January 25, 2011 9:47:35 am Philip Soeberg wrote: > Hi, > > I'm in a particular problem where I need to set my custom pcie adapter > into d3hot power-mode and a couple of seconds later reset it back to d0. > The board has an FPGA directly attached to the pcie interface, and as I > need to re-configure the FPGA on the fly, I have to ensure the datalink > layer between the upstream bridge and my device is idle to prevent any > hickups. > > On linux I simply do a pci_save_state(device) followed by > pci_set_power_state(device, d3hot), then after my magic on my board, I > do the reverse: pci_set_power_state(device, d0) followed by > pci_restore_state(device). > > On FreeBSD, say 8, I've found the pci_set_powerstate function, which is > documented in PCI(9), but that function does not save nor restore the > config space. > > I've tried, just for the fun of it, to go via pci_cfg_save(device, > dinfo, 0) with dinfo being device_get_ivars(device) and then > subsequently restoring the config space back via pci_cfg_restore(), but > since both those functions are declared in I'm > not sure if I'm supposed to use those directly or not.. Besides, I'm not > really having any luck with that approach. > > Reading high and low on the net suggest that not all too many driver > devs are concerned with suspend/resume operation of their device, and if > they are, leave it to user-space to decide when to suspend/resume a > device.. I would like to be able to save off my device' config space, > put it to sleep (d3hot), wake it back up (d0) and restore the device' > config space directly from the device' own driver.. > > Anyone who can help me with this? Use this: pci_cfg_save(dev, dinfo, 0); pci_set_powerstate(dev, PCI_POWERSTATE_D3); /* do stuff */ /* Will set state to D0. */ pci_cfg_restore(dev, dinfo); We probably should create some wrapper routines (pci_save_state() and pci_restore_state() would be fine) that hide the 'dinfo' detail as that isn't something device drivers should have to know. -- John Baldwin