From owner-freebsd-current@FreeBSD.ORG Tue Apr 12 13:15:45 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E0C8A16A4CF for ; Tue, 12 Apr 2005 13:15:45 +0000 (GMT) Received: from arginine.spc.org (arginine.spc.org [83.167.185.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id D6DFE43D45 for ; Tue, 12 Apr 2005 13:15:44 +0000 (GMT) (envelope-from bms@spc.org) Received: from localhost (localhost [127.0.0.1]) by arginine.spc.org (Postfix) with ESMTP id 7015C651FA for ; Tue, 12 Apr 2005 14:15:25 +0100 (BST) Received: from arginine.spc.org ([127.0.0.1]) by localhost (arginine.spc.org [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 36163-01 for ; Tue, 12 Apr 2005 14:15:24 +0100 (BST) Received: from empiric.dek.spc.org (dhcp52.icir.org [192.150.187.52]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by arginine.spc.org (Postfix) with ESMTP id C08C3651EB for ; Tue, 12 Apr 2005 14:15:23 +0100 (BST) Received: by empiric.dek.spc.org (Postfix, from userid 1001) id C1FF9616D; Tue, 12 Apr 2005 06:15:35 -0700 (PDT) Date: Tue, 12 Apr 2005 06:15:35 -0700 From: Bruce M Simpson To: freebsd-current@freebsd.org Message-ID: <20050412131535.GA784@empiric.icir.org> Mail-Followup-To: freebsd-current@freebsd.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline Subject: [PATCH] Allow pciconf(8) to be used with CardBus devices X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2005 13:15:46 -0000 --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, Here is a patch which allows pciconf to manipulate configuration space registers on CardBus devices, in addition to devices which are direct children of "pci" instances. The patch is against branch RELENG_5_4. If there are no objections I'd like to commit it to -HEAD. Thanks, BMS --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cardbus_pciconf.patch" Index: /usr/src/sys/dev/pci/pci_user.c =================================================================== RCS file: /home/ncvs/src/sys/dev/pci/pci_user.c,v retrieving revision 1.17 diff -u -p -r1.17 pci_user.c --- /usr/src/sys/dev/pci/pci_user.c 16 Jun 2004 09:46:53 -0000 1.17 +++ /usr/src/sys/dev/pci/pci_user.c 12 Apr 2005 12:54:15 -0000 @@ -173,7 +173,7 @@ pci_conf_match(struct pci_match_conf *ma static int pci_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) { - device_t pci, pcib; + device_t pcidev; struct pci_io *io; const char *name; int error; @@ -386,20 +386,23 @@ getconfexit: io->pi_reg + io->pi_width > PCI_REGMAX || io->pi_reg & (io->pi_width - 1)) error = EINVAL; - /* * Assume that the user-level bus number is - * actually the pciN instance number. We map - * from that to the real pcib+bus combination. + * in fact the physical PCI bus number. + * Look up the grandparent, i.e. the bridge device, + * so that we can issue configuration space cycles. */ - pci = devclass_get_device(devclass_find("pci"), - io->pi_sel.pc_bus); - if (pci) { - int b = pcib_get_bus(pci); - pcib = device_get_parent(pci); + pcidev = pci_find_bsf(io->pi_sel.pc_bus, + io->pi_sel.pc_dev, io->pi_sel.pc_func); + if (pcidev) { + device_t busdev, brdev; + + busdev = device_get_parent(pcidev); + brdev = device_get_parent(busdev); + if (cmd == PCIOCWRITE) - PCIB_WRITE_CONFIG(pcib, - b, + PCIB_WRITE_CONFIG(brdev, + io->pi_sel.pc_bus, io->pi_sel.pc_dev, io->pi_sel.pc_func, io->pi_reg, @@ -407,8 +410,8 @@ getconfexit: io->pi_width); else io->pi_data = - PCIB_READ_CONFIG(pcib, - b, + PCIB_READ_CONFIG(brdev, + io->pi_sel.pc_bus, io->pi_sel.pc_dev, io->pi_sel.pc_func, io->pi_reg, --y0ulUmNC+osPPQO6--