From owner-freebsd-hackers Tue Sep 19 7: 0:37 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from astart2.astart.com (astart2.astart.com [64.63.58.122]) by hub.freebsd.org (Postfix) with ESMTP id C7E4B37B422 for ; Tue, 19 Sep 2000 07:00:32 -0700 (PDT) Received: from h4.private (papowell@h4.private [10.0.0.4]) by astart2.astart.com (8.9.3/8.9.3) with ESMTP id XAA44396; Mon, 18 Sep 2000 23:59:41 -0700 (PDT) (envelope-from papowell@astart.com) Received: (from papowell@localhost) by h4.private (8.9.3/8.9.3) id HAA16643; Tue, 19 Sep 2000 07:01:33 -0700 (PDT) Date: Tue, 19 Sep 2000 07:01:33 -0700 (PDT) From: papowell@astart.com Message-Id: <200009191401.HAA16643@h4.private> To: imp@village.org, papowell@astart.com Subject: Re: Device driver, memory map failing, and it is probably obvious Cc: freebsd-hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > From owner-freebsd-hackers@FreeBSD.ORG Sun Sep 17 20:03:11 2000 > To: papowell@astart.com > Subject: Re: Device driver, memory map failing, and it is probably obvious > Cc: freebsd-hackers@FreeBSD.ORG > Date: Sun, 17 Sep 2000 21:01:44 -0600 > From: Warner Losh > > In message <200009180220.TAA12263@h4.private> papowell@astart.com writes: > : I am making a driver for a VERY old PCI device. > : > digic->digic_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, > : > &digic->digic_mem_rid, > : > 0, ~0, 256, RF_ACTIVE|RF_SHAREABLE); > > : Could this be the problem? > > Where do you initialize digic_mem_rid? You should set this equal to > the BAR offset in the PCI config space that corresponds to this > memory. > > Warner > BINGO! I added the following: /* now get the memory resources */ digic->digic_mem_rid = DIGI_LOMEM; digic->digic_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &digic->digic_mem_rid, 0, ~0, 256, RF_ACTIVE|RF_SHAREABLE); By the way, from the bus_alloc_resource man page: /* now get the memory resources */ digic->digic_mem_rid = DIGI_LOMEM; digic->digic_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &digic->digic_mem_rid, 0, ~0, 256, RF_ACTIVE|RF_SHAREABLE); > rid points to a bus specific handle that identifies the resource being > allocated. For ISA this is an index into an array of resources that have > been setup for this device by either the PnP mechanism, or via the hints > mechanism. For PCCARD, similar things are used as of writing, but that > may change in the future with newcard. For PCI it just happens to be the > offset into pci config space which has a word that describes the re- > source. The bus methods are free to change the RIDs that they are given > as a parameter. You must not depend on the value you gave it earlier. I might suggest a small rewording: rid points to a value that contains a bus specific handle that identifies the resource being allocated. For ISA this is an index into an array of resources that have been setup for this device by either the PnP mechanism, or via the hints mechanism. A value of 0 will use the first resource. See XXXXX for more details. For PCCARD, similar things are used as of writing, but that may change in the future with newcard. For PCI it is the offset into pci config space which has a word that describes the re- source. The bus methods are may change the values of the RIDs that they are given as a parameter. You must not depend on the value you gave it earlier. You might want to fill in XXXXX. EXAMPLES This is an example for an ISA bus interface. The values of portid and irqid should be saved in the softc of the device after these calls. struct resource *portres, irqres; int portid, irqid, value; #define REG1_OFFSET 0 portid = 0; /* use the first port resource */ irqid = 0; /* use the first interrupt resource */ portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid, 0ul, ~0ul, 32, RF_ACTIVE); irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &irqid, 0ul, ~0ul, 1, RF_ACTIVE | RF_SHAREABLE); value = bus_space_read_1( rman_get_bustag(portres), rman_get_bustag(portres), REG1_OFFSET ); This is an example for a PCI bus interface. We assume that for this particular device the device registers are available through PIO instructions or have been mapped into the PCI memory space. We can choose which method we want to use by setting the rid value to the appropriate offset in the PCI configuration that has the IO port or memory information. struct resource *portres; int portid, value; #define REG1_OFFSET 0 #define LOMEM 0x10 #define LOIO 0x14 if( use_io ){ portid = LOIO; } else { portid = LOMEM; } portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid, 0ul, ~0ul, 32, RF_ACTIVE); value = bus_space_read_1( rman_get_bustag(portres), rman_get_bustag(portres), REG1_OFFSET ); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message