A few notes:

1) Make sure that your device is really supporting 32-bit accesses.
2) Make sure that the addresses are *correct*.
3) Is the type of regr correct -- you're not doing any arithmetic on it, are you? 4) Check the "reg" property to make sure it is sane... look with prtconf -vp, and then read the pci(4) man page to decode it.

The rest of it looks *reasonable* to me. I suspect your problem lies in the code that you've elided with "..." ;-)

   -- Garrett


Adam Chunn wrote:
Hello all,

I am writing a device driver for a PCIe storage device and I am having trouble getting it off the ground.

When I attempt to access my device's registers using ddi_get32(), I get back 0xffffffff when I should be getting back 0xcafebeef.

I assume I am missing some setup somewhere, but I can't figure out where.

My code looks like this:

   static struct ddi_device_acc_attr dev_attr = {
       DDI_DEVICE_ATTR_V0,
       DDI_STRUCTURE_LE_ACC,
       DDI_STRICTORDER_ACC,
       DDI_DEFAULT_ACC
   };

   ddi_acc_handle_t regh;
   uint32_t *regh;

   static int pflash_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) {
       uint32_t val;
       :
       /* This maps all 64k of the first BAR */
ddi_regs_map_setup(dip, 1, (caddr_t *)&regr, 0, 0, &dev_attr, &regh);
       :
       val = ddi_get32(regh, regh);
       cmn_err(CE_NOTE, "val = %x", val);
       :

When I add my driver see the following in /var/adm/messages:

   <date time sys> pflash: [ID 768250 kern.notice] NOTICE: val = ffffffff

When I use a PCI bus analyzer on my PCIe device, I see the hardware respond to the register access with the data I expect. I just don't get the data I expect in val.

If I write the register prior to reading it, like so:

   ddi_put32(regh, regr, 0xdeaddead);
   val = ddi_get32(regh, regr);
   cmn_err(CE_NOTE, "val = %x", val);

I get the same print in my /var/adm/messages that I did before. Looking at my PCI bus analyzer, I see the correct write data, 0xdeaddead, written and read from the device's register space.

I have no idea why my driver would fail to give me my data. Can anyone point me in the correct direction? I assume I am missing a step somewhere.

Thanks,

-Adam

_______________________________________________
driver-discuss mailing list
driver-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/driver-discuss

_______________________________________________
driver-discuss mailing list
driver-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/driver-discuss

Reply via email to