drm: userspace rip out TTM API
[platform/upstream/libdrm.git] / shared-core / radeon_ms_rom.c
1 /*
2  * Copyright 2007 Jérôme Glisse
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * Authors:
26  *    Jerome Glisse <glisse@freedesktop.org>
27  */
28 #include "radeon_ms.h"
29
30 int radeon_ms_rom_get_properties(struct drm_device *dev)
31 {
32         struct drm_radeon_private *dev_priv = dev->dev_private;
33
34         switch (dev_priv->rom.type) {
35         case ROM_COMBIOS:
36                 return radeon_ms_combios_get_properties(dev);
37         }
38         return 0;
39 }
40
41 int radeon_ms_rom_init(struct drm_device *dev)
42 {
43         struct drm_radeon_private *dev_priv = dev->dev_private;
44         struct radeon_ms_rom *rom = &dev_priv->rom;
45         void *rom_mapped;
46         char atomstr[5] = {0, 0, 0, 0, 0};
47         uint16_t *offset;
48
49         dev_priv->rom.type = ROM_UNKNOWN;
50         /* copy rom if any */
51         rom_mapped = pci_map_rom(dev->pdev, &rom->rom_size);
52         if (rom_mapped && rom->rom_size) {
53                 rom->rom_image = drm_alloc(rom->rom_size, DRM_MEM_DRIVER);
54                 if (rom->rom_image == NULL) {
55                         return -1;
56                 }
57                 memcpy(rom->rom_image, rom_mapped, rom->rom_size);
58                 DRM_INFO("[radeon_ms] ROM %d bytes copied\n", rom->rom_size);
59         } else {
60                 DRM_INFO("[radeon_ms] no ROM\n");
61                 return 0;
62         }
63         pci_unmap_rom(dev->pdev, rom_mapped);
64
65         if (rom->rom_image[0] != 0x55 || rom->rom_image[1] != 0xaa) {
66                 DRM_INFO("[radeon_ms] no ROM\n");
67                 DRM_INFO("[radeon_ms] ROM signature 0x55 0xaa missing\n");
68                 return 0;
69         }
70         offset = (uint16_t *)&rom->rom_image[ROM_HEADER];
71         memcpy(atomstr, &rom->rom_image[*offset + 4], 4);
72         if (!strcpy(atomstr, "ATOM") || !strcpy(atomstr, "MOTA")) {
73                 DRM_INFO("[radeon_ms] ATOMBIOS ROM detected\n");
74                 return 0;
75         } else {
76                 struct combios_header **header;
77                 
78                 header = &rom->rom.combios_header;
79                 if ((*offset + sizeof(struct combios_header)) > rom->rom_size) {
80                         DRM_INFO("[radeon_ms] wrong COMBIOS header offset\n");
81                         return -1;
82                 }
83                 dev_priv->rom.type = ROM_COMBIOS;
84                 *header = (struct combios_header *)&rom->rom_image[*offset];
85                 DRM_INFO("[radeon_ms] COMBIOS type  : %d\n",
86                          (*header)->ucTypeDefinition);
87                 DRM_INFO("[radeon_ms] COMBIOS  OEM ID: %02x %02x\n",
88                          (*header)->ucOemID1, (*header)->ucOemID2);
89         }
90         return 0;
91 }