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 __FBSDID("$FreeBSD$");
30 #include <dev/drm2/drmP.h>
32 static void drm_platform_free_irq(struct drm_device *dev)
34 if (dev->irqr == NULL)
37 bus_release_resource(dev->dev, SYS_RES_IRQ,
38 dev->irqrid, dev->irqr);
44 static const char *drm_platform_get_name(struct drm_device *dev)
46 return dev->driver->name;
49 static int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master)
53 master->unique_len = 13 + strlen(dev->driver->name);
54 master->unique_size = master->unique_len;
55 master->unique = malloc(master->unique_len + 1, DRM_MEM_DRIVER, M_NOWAIT);
57 if (master->unique == NULL)
60 id = 0; // XXX dev->driver->id;
62 /* if only a single instance of the platform device, id will be
63 * set to -1.. use 0 instead to avoid a funny looking bus-id:
68 len = snprintf(master->unique, master->unique_len,
69 "platform:%s:%02d", dev->driver->name, id);
71 if (len > master->unique_len) {
72 DRM_ERROR("Unique buffer overflowed\n");
82 static int drm_platform_get_irq(struct drm_device *dev)
87 dev->irqr = bus_alloc_resource_any(dev->dev, SYS_RES_IRQ,
88 &dev->irqrid, RF_SHAREABLE);
90 dev_err(dev->dev, "Failed to allocate IRQ\n");
94 dev->irq = (int) rman_get_start(dev->irqr);
99 static struct drm_bus drm_platform_bus = {
100 .bus_type = DRIVER_BUS_PLATFORM,
101 .get_irq = drm_platform_get_irq,
102 .free_irq = drm_platform_free_irq,
103 .get_name = drm_platform_get_name,
104 .set_busid = drm_platform_set_busid,
110 * \param platdev - Platform device struture
111 * \return zero on success or a negative number on failure.
113 * Attempt to gets inter module "drm" information. If we are first
114 * then register the character device and inter module information.
115 * Try and register, if we fail to register, backout previous work.
118 int drm_get_platform_dev(device_t kdev, struct drm_device *dev,
119 struct drm_driver *driver)
125 driver->bus = &drm_platform_bus;
129 sx_xlock(&drm_global_mutex);
131 ret = drm_fill_in_dev(dev, driver);
134 printf("DRM: Fill_in_dev failed.\n");
138 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
139 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
144 ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
148 if (dev->driver->load) {
149 ret = dev->driver->load(dev, 0);
154 /* setup the grouping for the legacy output */
155 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
156 ret = drm_mode_group_init_legacy_group(dev,
157 &dev->primary->mode_group);
162 #ifdef FREEBSD_NOTYET
163 list_add_tail(&dev->driver_item, &driver->device_list);
164 #endif /* FREEBSD_NOTYET */
166 sx_xunlock(&drm_global_mutex);
168 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
169 driver->name, driver->major, driver->minor, driver->patchlevel,
170 driver->date, dev->primary->index);
175 drm_put_minor(&dev->primary);
177 if (drm_core_check_feature(dev, DRIVER_MODESET))
178 drm_put_minor(&dev->control);
180 sx_xunlock(&drm_global_mutex);
183 EXPORT_SYMBOL(drm_get_platform_dev);