Date: Wed, 2 Sep 1998 09:22:48 -0400 (EDT) From: Bill Paul <wpaul@skynet.ctr.columbia.edu> To: wilko@yedi.iaf.nl (Wilko Bulte) Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: pci memory mapping Message-ID: <199809021322.JAA08429@skynet.ctr.columbia.edu> In-Reply-To: <199809012205.AAA29093@yedi.iaf.nl> from "Wilko Bulte" at Sep 2, 98 00:05:04 am
next in thread | previous in thread | raw e-mail | index | archive | help
Of all the gin joints in all the towns in all the world, Wilko Bulte had to walk into mine and say: > Hi there, > > I'm trying to get a Mylex DAC960PD to work with a driver skeleton Ulf > wrote. As I have a different Mylex board than Ulf (a PD iso a PG) I need > to make some changes. > > For some reason the followin code in attach() fails: > > if (!pci_map_mem(config_id, PCI_MAP_REG_START, &mp->vbase, > &mp->pbase)) { > printf("myx%d: couldn't map memory\n", unit); > goto fail; > } > > From a previous post by Bill Paul I get the impression (...) that I might need > to enable memory mapping by doing a pci_conf_write(). But what params > do I feed pci_conf_write()? Given that you learned this from a posting by Bill Paul, would it not then make sense to read the driver code that Bill Paul has recently written to see how he did it? :) > This is all new to me, I could really use some advise here. First of all, bear in mind that not every PCI device supports memory mapping of its registers. To find out if yours does or not, you need to check the device's manual or datasheet. It's also possible that the device does support memory mapped access but the 'memory map enable' bit in the command register is off. To turn it on, you need to do something like the following: u_int32_t command; /* read the PCI command register */ command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); /* set the memory map enable bit */ command |= PCIM_CMD_MEMEN; /* write it back to the register */ pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, command); /* check that it worked */ command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); if (!(command & PCIM_CMD_MEMEN)) printf("failed to enable memory mapped access!\n"); Note that this is for -current. The constant PCIM_CMD_MEMEN has a different name in 2.2.x. If you compare the XL driver from 3.0 and 2.2.x, you can see the differences. The constants are defined in /sys/pci/pcireg.h. This code should be used in the PCI attach routine: the PCI support code passes the attach function a PCI ID handle as the first argument, which is called config_id here. Ulf may have used a different variable name. If the bit doesn't come on after you write to the command register, it probably means the device doesn't actually support memory mapped access. In this case, the driver must use PIO access (inb/outb). For this, you must make sure the PCIM_CMD_PORTEN bit is set. Lastly, if the device is a bus master (and being a disk controller I suppose it would make sense that it would be) you should check that the PCIM_CMD_BUSMASTEREN bit is set too. I'm not certain why these bits are not always on, however I've heard nebulous statements that this has something to do with Windows turning them off and the PCI BIOS leaving that way. I decided to always try forcing them on just to cover myself. -Bill -- ============================================================================= -Bill Paul (212) 854-6020 | System Manager, Master of Unix-Fu Work: wpaul@ctr.columbia.edu | Center for Telecommunications Research Home: wpaul@skynet.ctr.columbia.edu | Columbia University, New York City ============================================================================= "It is not I who am crazy; it is I who am mad!" - Ren Hoek, "Space Madness" ============================================================================= To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809021322.JAA08429>