hal: Branch 'master' - 2 commits
Joe Marcus Clarke
marcus at kemper.freedesktop.org
Sun Jan 27 14:47:36 PST 2008
hald/freebsd/Makefile.am | 2
hald/freebsd/hf-devtree.c | 8 +
hald/freebsd/hf-drm.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++
hald/freebsd/hf-drm.h | 35 +++++++
hald/freebsd/hf-sound.h | 2
hald/freebsd/osspec.c | 2
6 files changed, 275 insertions(+), 1 deletion(-)
New commits:
commit 1b0a1f3ccb6694718acfcac845276577f681d745
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date: Sun Jan 27 17:47:30 2008 -0500
add DRM device support
Add support for Direct Rendering devices.
diff --git a/hald/freebsd/Makefile.am b/hald/freebsd/Makefile.am
index d71be3b..95d40d4 100644
--- a/hald/freebsd/Makefile.am
+++ b/hald/freebsd/Makefile.am
@@ -26,6 +26,8 @@ libhald_freebsd_la_SOURCES = \
hf-devd.h \
hf-devtree.c \
hf-devtree.h \
+ hf-drm.c \
+ hf-drm.h \
hf-net.c \
hf-net.h \
hf-osspec.h \
diff --git a/hald/freebsd/hf-devtree.c b/hald/freebsd/hf-devtree.c
index 964df09..dd2547d 100644
--- a/hald/freebsd/hf-devtree.c
+++ b/hald/freebsd/hf-devtree.c
@@ -369,6 +369,7 @@ static Handler handlers[] = {
{ "battery", hf_acpi_battery_set_properties },
{ "cardbus", hf_pcmcia_set_properties },
{ "cpu", hf_devtree_cpu_set_properties },
+ { "drm", NULL },
{ "fd", hf_devtree_fd_set_properties },
{ "fdc", NULL },
{ "joy", hf_devtree_joy_set_properties },
@@ -517,11 +518,18 @@ hf_devtree_find_parent_from_info (HalDeviceStore *store,
void
hf_devtree_device_set_info (HalDevice *device, const char *driver, int unit)
{
+ char *devfile;
+
g_return_if_fail(HAL_IS_DEVICE(device));
g_return_if_fail(driver != NULL);
hal_device_property_set_string(device, "freebsd.driver", driver);
hal_device_property_set_int(device, "freebsd.unit", unit);
+
+ devfile = g_strdup_printf("/dev/%s%i", driver, unit);
+ if (g_file_test(devfile, G_FILE_TEST_EXISTS))
+ hf_device_property_set_string_printf(device, "freebsd.device_file", "/dev/%s%i", driver, unit);
+ g_free(devfile);
}
gboolean
diff --git a/hald/freebsd/hf-drm.c b/hald/freebsd/hf-drm.c
new file mode 100644
index 0000000..5cee365
--- /dev/null
+++ b/hald/freebsd/hf-drm.c
@@ -0,0 +1,227 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * hf-drm.c : DRM (Direct Rendering) device support
+ *
+ * Copyright (C) 2008 Joe Marcus Clarke <marcus at FreeBSD.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "../logger.h"
+#include "../osspec.h"
+
+#include "hf-drm.h"
+#include "hf-devtree.h"
+#include "hf-util.h"
+
+#define HF_DRM_DEVICE "/dev/dri/card"
+
+typedef struct
+{
+ int major;
+ int minor;
+ int patchlevel;
+ unsigned long name_len;
+ char *name;
+ unsigned long date_len;
+ char *date;
+ unsigned long desc_len;
+ char *desc;
+} hf_drm_version_t;
+
+#define HF_DRM_VERSION_IOCTL _IOWR('d', 0x00, hf_drm_version_t)
+
+typedef struct
+{
+ int index;
+ hf_drm_version_t *drm_version;
+} Card;
+
+static GSList *cards = NULL;
+
+static Card *
+hf_drm_find_card (int index)
+{
+ GSList *l;
+
+ HF_LIST_FOREACH(l, cards)
+ {
+ Card *card = l->data;
+
+ if (card->index == index)
+ return card;
+ }
+
+ return NULL;
+}
+
+static void
+hf_drm_version_free (hf_drm_version_t *vers)
+{
+ g_return_if_fail(vers != NULL);
+
+ g_free(vers->name);
+ g_free(vers->date);
+ g_free(vers->desc);
+
+ g_free(vers);
+}
+
+static HalDevice *
+hf_drm_device_new (HalDevice *parent, Card *card)
+{
+ HalDevice *device;
+
+ g_return_val_if_fail(HAL_IS_DEVICE(parent), NULL);
+
+ device = hf_device_new(parent);
+
+ hal_device_add_capability(device, "drm");
+
+ if (card->drm_version->desc)
+ hal_device_property_set_string(device, "info.vendor", card->drm_version->desc);
+ hal_device_property_set_string(device, "info.product", "Direct Rendering Manager Device");
+ hal_device_property_set_string(device, "info.category", "drm");
+ hf_device_property_set_string_printf(device, "freebsd.device_file", HF_DRM_DEVICE "%i", card->index);
+ hal_device_property_set_string(device, "drm.dri_library", card->drm_version->name);
+ hf_device_property_set_string_printf(device, "drm.version", "drm %i.%i.%i %s", card->drm_version->major, card->drm_version->minor, card->drm_version->patchlevel, card->drm_version->date);
+
+ hf_device_set_full_udi(device, "%s_drm_%s_card%i", hal_device_get_udi(parent), card->drm_version->name, card->index);
+
+ return device;
+}
+
+static void
+hf_drm_privileged_init (void)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ {
+ char *filename;
+ int fd;
+
+ filename = g_strdup_printf(HF_DRM_DEVICE "%i", i);
+ fd = open(filename, O_RDONLY);
+ g_free(filename);
+
+ if (fd >= 0)
+ {
+ Card *card;
+ hf_drm_version_t *drm_version;
+ int res;
+
+ card = g_new0(Card, 1);
+ card->index = i;
+ drm_version = g_new0(hf_drm_version_t, 1);
+
+ res = ioctl(fd, HF_DRM_VERSION_IOCTL, drm_version);
+ if (res)
+ {
+ hf_drm_version_free(drm_version);
+ close(fd);
+ continue;
+ }
+
+ if (drm_version->name_len)
+ drm_version->name = g_malloc(drm_version->name_len + 1);
+ if (drm_version->date_len)
+ drm_version->date = g_malloc(drm_version->date_len + 1);
+ if (drm_version->desc_len)
+ drm_version->desc = g_malloc(drm_version->desc_len + 1);
+
+ res = ioctl(fd, HF_DRM_VERSION_IOCTL, drm_version);
+ if (res)
+ {
+ hf_drm_version_free(drm_version);
+ close(fd);
+ continue;
+ }
+
+ if (drm_version->name)
+ drm_version->name[drm_version->name_len] = '\0';
+ if (drm_version->date)
+ drm_version->date[drm_version->date_len] = '\0';
+ if (drm_version->desc)
+ drm_version->desc[drm_version->desc_len] = '\0';
+
+ if (! drm_version->name || ! drm_version->date)
+ {
+ hf_drm_version_free(drm_version);
+ close(fd);
+ continue;
+ }
+
+ card->drm_version = drm_version;
+ close(fd);
+
+ cards = g_slist_append(cards, card);
+ }
+ }
+}
+
+static void
+hf_drm_probe (void)
+{
+ GSList *drm_devices, *l;
+
+ if (! cards)
+ return;
+
+ drm_devices = hal_device_store_match_multiple_key_value_string(hald_get_gdl(),
+ "freebsd.driver", "drm");
+ HF_LIST_FOREACH(l, drm_devices)
+ {
+ HalDevice *parent = HAL_DEVICE(l->data);
+
+ if (! hal_device_property_get_bool(parent, "info.ignore"))
+ {
+ Card *card;
+ HalDevice *device;
+ int unit;
+
+ unit = hal_device_property_get_int(parent, "freebsd.unit");
+ card = hf_drm_find_card(unit);
+
+ if (! card)
+ continue;
+
+ device = hf_drm_device_new(parent, card);
+
+ if (device)
+ hf_device_preprobe_and_add(device);
+ }
+ }
+ g_slist_free(drm_devices);
+}
+
+HFHandler hf_drm_handler =
+{
+ .privileged_init = hf_drm_privileged_init,
+ .probe = hf_drm_probe
+};
diff --git a/hald/freebsd/hf-drm.h b/hald/freebsd/hf-drm.h
new file mode 100644
index 0000000..20302be
--- /dev/null
+++ b/hald/freebsd/hf-drm.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * hf-drm.h : DRM (Direct Rendering) device support
+ *
+ * Copyright (C) 2008 Joe Marcus Clarke <marcus at FreeBSD.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifndef _HF_DRM_H
+#define _HF_DRM_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "hf-osspec.h"
+
+extern HFHandler hf_drm_handler;
+
+#endif /* _HF_DRM_H */
diff --git a/hald/freebsd/osspec.c b/hald/freebsd/osspec.c
index b7140d7..38ab181 100644
--- a/hald/freebsd/osspec.c
+++ b/hald/freebsd/osspec.c
@@ -38,6 +38,7 @@
#include "hf-computer.h"
#include "hf-devd.h"
#include "hf-devtree.h"
+#include "hf-drm.h"
#include "hf-net.h"
#include "hf-pci.h"
#include "hf-scsi.h"
@@ -60,6 +61,7 @@ static HFHandler *handlers[] = {
&hf_serial_handler,
&hf_acpi_handler,
&hf_sound_handler,
+ &hf_drm_handler,
&hf_devd_handler
};
commit ae67693bcc252e4ac3c65ded8515742d17a4493e
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date: Sun Jan 27 17:46:20 2008 -0500
correct a comment
Specify the correct name for this header in the copyright comment.
diff --git a/hald/freebsd/hf-sound.h b/hald/freebsd/hf-sound.h
index 3c9ef2a..f12883f 100644
--- a/hald/freebsd/hf-sound.h
+++ b/hald/freebsd/hf-sound.h
@@ -1,7 +1,7 @@
/***************************************************************************
* CVSID: $Id$
*
- * hf-net.h : sound (OSS) device support
+ * hf-sound.h : sound (OSS) device support
*
* Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
*
More information about the hal-commit
mailing list