[Pommed-commits] [SCM] pommed - hotkeys handler for Apple laptops branch, master, updated. 1.25-10-gd4d3b61
Julien BLACHE
jb at jblache.org
Sat Mar 14 10:35:10 UTC 2009
The following commit has been merged in the master branch:
commit d4d3b6184d76204c74cdd56f02526ce7943ebc82
Author: Julien BLACHE <jb at jblache.org>
Date: Sat Mar 14 11:32:09 2009 +0100
Switch to sysfs resource files for PCI resource access
mmaping /dev/mem is deprecated for PCI resource access.
As a bonus, we don't rely on libpci for critical memory addresses anymore.
diff --git a/ChangeLog b/ChangeLog
index 73ef169..682f026 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,10 @@ ChangeLog for pommed
version 1.26:
- pommed: only keystrokes on the built-in keyboard should reset
the keyboard idle timer.
- - pommed: add USB IDs for the Apple external aluminium mini keyboard.
+ - pommed: add USB IDs for the Apple external aluminium mini
+ keyboard.
+ - pommed: switch to sysfs resource files for PCI memory access
+ instead of mmaping /dev/mem.
version 1.25:
- pommed: check current hardware backlight level before setting AC
diff --git a/pommed/mactel/gma950_backlight.c b/pommed/mactel/gma950_backlight.c
index 6af2a86..ee5ef27 100644
--- a/pommed/mactel/gma950_backlight.c
+++ b/pommed/mactel/gma950_backlight.c
@@ -72,7 +72,7 @@ static unsigned int GMA950_BACKLIGHT_MAX;
static int fd = -1;
static char *memory = NULL;
-static long address = 0;
+static char sysfs_resource[64];
static long length = 0;
#define REGISTER_OFFSET 0x00061254
@@ -121,21 +121,21 @@ gma950_backlight_set(unsigned int value)
static int
gma950_backlight_map(void)
{
- if ((address == 0) || (length == 0))
+ if (length == 0)
{
logdebug("No probing done !\n");
return -1;
}
- fd = open("/dev/mem", O_RDWR);
+ fd = open(sysfs_resource, O_RDWR);
if (fd < 0)
{
- logmsg(LOG_WARNING, "Cannot open /dev/mem: %s", strerror(errno));
+ logmsg(LOG_WARNING, "Cannot open %s: %s", sysfs_resource, strerror(errno));
return -1;
}
- memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, address);
+ memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (memory == MAP_FAILED)
{
@@ -311,6 +311,7 @@ gma950_backlight_probe(void)
{
struct pci_access *pacc;
struct pci_dev *dev;
+ struct stat stbuf;
int card;
int ret;
@@ -329,7 +330,7 @@ gma950_backlight_probe(void)
/* Iterate over all devices */
for(dev = pacc->devices; dev; dev = dev->next)
{
- pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
+ pci_fill_info(dev, PCI_FILL_IDENT);
/* GMA950 or GMA965 */
if ((dev->vendor_id == PCI_ID_VENDOR_INTEL)
&& ((dev->device_id == PCI_ID_PRODUCT_GMA950)
@@ -337,8 +338,9 @@ gma950_backlight_probe(void)
{
card = dev->device_id;
- address = dev->base_addr[0];
- length = dev->size[0];
+ ret = snprintf(sysfs_resource, sizeof(sysfs_resource),
+ "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource0",
+ dev->domain, dev->bus, dev->dev, dev->func);
break;
}
@@ -346,12 +348,30 @@ gma950_backlight_probe(void)
pci_cleanup(pacc);
- if (!address)
+ if (!dev)
{
logdebug("Failed to detect Intel GMA950 or GMA965, aborting...\n");
return -1;
}
+ /* Check snprintf() return value */
+ if (ret >= sizeof(sysfs_resource))
+ {
+ logmsg(LOG_ERR, "Could not build sysfs PCI resource path");
+ return -1;
+ }
+
+ ret = stat(sysfs_resource, &stbuf);
+ if (ret < 0)
+ {
+ logmsg(LOG_ERR, "Could not determine PCI resource length: %s", strerror(errno));
+ return -1;
+ }
+
+ length = stbuf.st_size;
+
+ logdebug("GMA950/GMA965 PCI resource: [%s], length %ldK\n", sysfs_resource, (length / 1024));
+
ret = gma950_backlight_map();
if (ret < 0)
{
diff --git a/pommed/mactel/x1600_backlight.c b/pommed/mactel/x1600_backlight.c
index 735cb3c..ef1c720 100644
--- a/pommed/mactel/x1600_backlight.c
+++ b/pommed/mactel/x1600_backlight.c
@@ -47,10 +47,9 @@
struct _lcd_bck_info lcd_bck_info;
-
static int fd = -1;
static char *memory = NULL;
-static long address = 0;
+static char sysfs_resource[64];
static long length = 0;
static inline unsigned int
@@ -87,17 +86,17 @@ x1600_backlight_map(void)
{
unsigned int state;
- if ((address == 0) || (length == 0))
+ if (length == 0)
{
- logdebug("No probing done !\n");
+ logdebug("No probing done!\n");
return -1;
}
- fd = open("/dev/mem", O_RDWR);
+ fd = open(sysfs_resource, O_RDWR);
if (fd < 0)
{
- logmsg(LOG_WARNING, "Cannot open /dev/mem: %s", strerror(errno));
+ logmsg(LOG_WARNING, "Cannot open %s: %s", sysfs_resource, strerror(errno));
close(fd);
fd = -1;
@@ -105,7 +104,7 @@ x1600_backlight_map(void)
return -1;
}
- memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, address);
+ memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (memory == MAP_FAILED)
{
@@ -246,6 +245,7 @@ x1600_backlight_probe(void)
{
struct pci_access *pacc;
struct pci_dev *dev;
+ struct stat stbuf;
int ret;
@@ -262,13 +262,14 @@ x1600_backlight_probe(void)
/* Iterate over all devices */
for(dev = pacc->devices; dev; dev = dev->next)
{
- pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
+ pci_fill_info(dev, PCI_FILL_IDENT);
/* ATI X1600 */
if ((dev->vendor_id == PCI_ID_VENDOR_ATI)
&& (dev->device_id == PCI_ID_PRODUCT_X1600))
{
- address = dev->base_addr[2];
- length = dev->size[2];
+ ret = snprintf(sysfs_resource, sizeof(sysfs_resource),
+ "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource2",
+ dev->domain, dev->bus, dev->dev, dev->func);
break;
}
@@ -276,12 +277,30 @@ x1600_backlight_probe(void)
pci_cleanup(pacc);
- if (!address)
+ if (!dev)
{
logdebug("Failed to detect ATI X1600, aborting...\n");
return -1;
}
+ /* Check snprintf() return value */
+ if (ret >= sizeof(sysfs_resource))
+ {
+ logmsg(LOG_ERR, "Could not build sysfs PCI resource path");
+ return -1;
+ }
+
+ ret = stat(sysfs_resource, &stbuf);
+ if (ret < 0)
+ {
+ logmsg(LOG_ERR, "Could not determine PCI resource length: %s", strerror(errno));
+ return -1;
+ }
+
+ length = stbuf.st_size;
+
+ logdebug("ATI X1600 PCI resource: [%s], length %ldK\n", sysfs_resource, (length / 1024));
+
lcd_bck_info.max = X1600_BACKLIGHT_MAX;
ret = x1600_backlight_map();
--
pommed - hotkeys handler for Apple laptops
More information about the Pommed-commits
mailing list