From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 7 19:29:43 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org 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 CB7F816A4DA for ; Mon, 7 Aug 2006 19:29:43 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0768343D5C for ; Mon, 7 Aug 2006 19:29:31 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.6/8.13.6) with ESMTP id k77JTN4S036769; Mon, 7 Aug 2006 15:29:26 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 7 Aug 2006 15:27:50 -0400 User-Agent: KMail/1.9.1 References: <44D4A5DC.7080403@cytexbg.com> In-Reply-To: <44D4A5DC.7080403@cytexbg.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200608071527.50711.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 07 Aug 2006 15:29:27 -0400 (EDT) X-Virus-Scanned: ClamAV 0.87.1/1639/Mon Aug 7 09:34:09 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: Subject: Re: jkh weird problem (reading pci device memory) 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: Mon, 07 Aug 2006 19:29:43 -0000 On Saturday 05 August 2006 10:06, Niki Denev wrote: > for(i=0; i < sizeof(config_table_t); i++) { > r = bus_space_read_1(sc->bar.tag, sc->bar.hdl, i); > *((u_int8_t *)&sc->cfg_table + i) = r; > } Note that you can replace this with: bus_space_read_multi_1(sc->bar.tag, sc->bar.hdl, 0, (u_int8_t *)&sc->cfg_table, sizeof(config_table_t)); However, if you are really reading in a table with more than just chars, you might want to read the individual fields and byteswap them as needed (if you care about portability to a big-endian arch like sparc). That is, if your device stores the table as little-endian and you had: typedef struct _config_table { uint32_t signature; uint16_t version; uint8_t dummy; } config_table_t; You would do this instead: sc->cfg_table.signature = letoh32(bus_read_4(sc->bar.res, 0)); sc->cfg_table.version = letoh16(bus_read_2(sc->bar.res, 4)); sc->cfg_table.dummy = bus_read_1(sc->bar.res, 5); (Note this also uses the shorter bus_read functions which just take a struct resouce *.) I have no idea why the printf's make a difference, unless perhaps your card needs a bit of a delay after it is inserted before it's firmware is fully up and running. In that case you might want to insert a delay. Something like this: /* XXX: Doesn't it want to print rman_get_size() / 1024 instead? */ device_printf(dev, "card has %uKB memory\n", sc->card_type); count = 0; while (letoh32(bus_read_4(sc->bar.res, 0)) != CONFIG_MAGIC) { /* If it's not up after a half-second, give up. */ if (count > 50) { device_printf(dev, "ConfigTable Bad!\n"); return (ENXIO); } count++; /* Wait 10 ms. */ DELAY(10000); } -- John Baldwin