2 * Derived from drm_pci.c
4 * Copyright 2003 José Fonseca.
5 * Copyright 2003 Leif Delgass.
6 * Copyright (c) 2009, Code Aurora Forum.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <sys/cdefs.h>
28 #include <dev/drm2/drmP.h>
30 static void drm_platform_free_irq(struct drm_device *dev)
32 if (dev->irqr == NULL)
35 bus_release_resource(dev->dev, SYS_RES_IRQ,
36 dev->irqrid, dev->irqr);
42 static const char *drm_platform_get_name(struct drm_device *dev)
44 return dev->driver->name;
47 static int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master)
51 master->unique_len = 13 + strlen(dev->driver->name);
52 master->unique_size = master->unique_len;
53 master->unique = malloc(master->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT);
55 if (master->unique == NULL)
58 id = 0; // XXX dev->driver->id;
60 /* if only a single instance of the platform device, id will be
61 * set to -1.. use 0 instead to avoid a funny looking bus-id:
66 len = snprintf(master->unique, master->unique_len,
67 "platform:%s:%02d", dev->driver->name, id);
69 if (len > master->unique_len) {
70 DRM_ERROR("Unique buffer overflowed\n");
80 static int drm_platform_get_irq(struct drm_device *dev)
85 dev->irqr = bus_alloc_resource_any(dev->dev, SYS_RES_IRQ,
86 &dev->irqrid, RF_SHAREABLE);
88 dev_err(dev->dev, "Failed to allocate IRQ\n");
92 dev->irq = (int) rman_get_start(dev->irqr);
97 static struct drm_bus drm_platform_bus = {
98 .bus_type = DRIVER_BUS_PLATFORM,
99 .get_irq = drm_platform_get_irq,
100 .free_irq = drm_platform_free_irq,
101 .get_name = drm_platform_get_name,
102 .set_busid = drm_platform_set_busid,
108 * \param platdev - Platform device structure
109 * \return zero on success or a negative number on failure.
111 * Attempt to gets inter module "drm" information. If we are first
112 * then register the character device and inter module information.
113 * Try and register, if we fail to register, backout previous work.
116 int drm_get_platform_dev(device_t kdev, struct drm_device *dev,
117 struct drm_driver *driver)
123 driver->bus = &drm_platform_bus;
127 sx_xlock(&drm_global_mutex);
129 ret = drm_fill_in_dev(dev, driver);
132 printf("DRM: Fill_in_dev failed.\n");
136 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
137 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
142 ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
146 if (dev->driver->load) {
147 ret = dev->driver->load(dev, 0);
152 /* setup the grouping for the legacy output */
153 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
154 ret = drm_mode_group_init_legacy_group(dev,
155 &dev->primary->mode_group);
160 #ifdef FREEBSD_NOTYET
161 list_add_tail(&dev->driver_item, &driver->device_list);
162 #endif /* FREEBSD_NOTYET */
164 sx_xunlock(&drm_global_mutex);
166 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
167 driver->name, driver->major, driver->minor, driver->patchlevel,
168 driver->date, dev->primary->index);
173 drm_put_minor(&dev->primary);
175 if (drm_core_check_feature(dev, DRIVER_MODESET))
176 drm_put_minor(&dev->control);
178 sx_xunlock(&drm_global_mutex);
181 EXPORT_SYMBOL(drm_get_platform_dev);