Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Framebuffer driver for EFI/UEFI based system |
| 3 | * |
| 4 | * (c) 2006 Edgar Hucek <gimli@dark-green.com> |
| 5 | * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/fb.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/screen_info.h> |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 15 | #include <linux/dmi.h> |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 16 | #include <linux/pci.h> |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 17 | #include <video/vga.h> |
| 18 | |
Henrik Kretzschmar | ec81c9c | 2010-08-10 18:02:28 -0700 | [diff] [blame] | 19 | static struct fb_var_screeninfo efifb_defined __devinitdata = { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 20 | .activate = FB_ACTIVATE_NOW, |
| 21 | .height = -1, |
| 22 | .width = -1, |
| 23 | .right_margin = 32, |
| 24 | .upper_margin = 16, |
| 25 | .lower_margin = 4, |
| 26 | .vsync_len = 4, |
| 27 | .vmode = FB_VMODE_NONINTERLACED, |
| 28 | }; |
| 29 | |
Henrik Kretzschmar | ec81c9c | 2010-08-10 18:02:28 -0700 | [diff] [blame] | 30 | static struct fb_fix_screeninfo efifb_fix __devinitdata = { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 31 | .id = "EFI VGA", |
| 32 | .type = FB_TYPE_PACKED_PIXELS, |
| 33 | .accel = FB_ACCEL_NONE, |
| 34 | .visual = FB_VISUAL_TRUECOLOR, |
| 35 | }; |
| 36 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 37 | enum { |
| 38 | M_I17, /* 17-Inch iMac */ |
| 39 | M_I20, /* 20-Inch iMac */ |
| 40 | M_I20_SR, /* 20-Inch iMac (Santa Rosa) */ |
| 41 | M_I24, /* 24-Inch iMac */ |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 42 | M_I24_8_1, /* 24-Inch iMac, 8,1th gen */ |
| 43 | M_I24_10_1, /* 24-Inch iMac, 10,1th gen */ |
| 44 | M_I27_11_1, /* 27-Inch iMac, 11,1th gen */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 45 | M_MINI, /* Mac Mini */ |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 46 | M_MINI_3_1, /* Mac Mini, 3,1th gen */ |
| 47 | M_MINI_4_1, /* Mac Mini, 4,1th gen */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 48 | M_MB, /* MacBook */ |
| 49 | M_MB_2, /* MacBook, 2nd rev. */ |
| 50 | M_MB_3, /* MacBook, 3rd rev. */ |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 51 | M_MB_5_1, /* MacBook, 5th rev. */ |
| 52 | M_MB_6_1, /* MacBook, 6th rev. */ |
| 53 | M_MB_7_1, /* MacBook, 7th rev. */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 54 | M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */ |
| 55 | M_MBA, /* MacBook Air */ |
Matthew Garrett | 97fb850 | 2011-04-06 17:34:59 +0000 | [diff] [blame] | 56 | M_MBA_3, /* Macbook Air, 3rd rev */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 57 | M_MBP, /* MacBook Pro */ |
| 58 | M_MBP_2, /* MacBook Pro 2nd gen */ |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 59 | M_MBP_2_2, /* MacBook Pro 2,2nd gen */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 60 | M_MBP_SR, /* MacBook Pro (Santa Rosa) */ |
| 61 | M_MBP_4, /* MacBook Pro, 4th gen */ |
Thomas Gerlach | 8a3bdfe | 2010-04-23 13:17:50 -0400 | [diff] [blame] | 62 | M_MBP_5_1, /* MacBook Pro, 5,1th gen */ |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 63 | M_MBP_5_2, /* MacBook Pro, 5,2th gen */ |
| 64 | M_MBP_5_3, /* MacBook Pro, 5,3rd gen */ |
| 65 | M_MBP_6_1, /* MacBook Pro, 6,1th gen */ |
| 66 | M_MBP_6_2, /* MacBook Pro, 6,2th gen */ |
| 67 | M_MBP_7_1, /* MacBook Pro, 7,1th gen */ |
Davidlohr Bueso | e9c5db0 | 2011-03-31 00:12:22 +0000 | [diff] [blame] | 68 | M_MBP_8_2, /* MacBook Pro, 8,2nd gen */ |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 69 | M_UNKNOWN /* placeholder */ |
| 70 | }; |
| 71 | |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 72 | #define OVERRIDE_NONE 0x0 |
| 73 | #define OVERRIDE_BASE 0x1 |
| 74 | #define OVERRIDE_STRIDE 0x2 |
| 75 | #define OVERRIDE_HEIGHT 0x4 |
| 76 | #define OVERRIDE_WIDTH 0x8 |
| 77 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 78 | static struct efifb_dmi_info { |
| 79 | char *optname; |
| 80 | unsigned long base; |
| 81 | int stride; |
| 82 | int width; |
| 83 | int height; |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 84 | int flags; |
Henrik Kretzschmar | ec81c9c | 2010-08-10 18:02:28 -0700 | [diff] [blame] | 85 | } dmi_list[] __initdata = { |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 86 | [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE }, |
| 87 | [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, /* guess */ |
| 88 | [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050, OVERRIDE_NONE }, |
| 89 | [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, /* guess */ |
| 90 | [M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, |
| 91 | [M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080, OVERRIDE_NONE }, |
| 92 | [M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440, OVERRIDE_NONE }, |
| 93 | [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768, OVERRIDE_NONE }, |
| 94 | [M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768, OVERRIDE_NONE }, |
| 95 | [M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, |
| 96 | [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
| 97 | [M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
| 98 | [M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
| 99 | [M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
| 100 | [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
Matthew Garrett | 97fb850 | 2011-04-06 17:34:59 +0000 | [diff] [blame] | 101 | /* 11" Macbook Air 3,1 passes the wrong stride */ |
| 102 | [M_MBA_3] = { "mba3", 0, 2048 * 4, 0, 0, OVERRIDE_STRIDE }, |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 103 | [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE }, |
| 104 | [M_MBP_2] = { "mbp2", 0, 0, 0, 0, OVERRIDE_NONE }, /* placeholder */ |
| 105 | [M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900, OVERRIDE_NONE }, |
| 106 | [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900, OVERRIDE_NONE }, |
| 107 | [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, |
| 108 | [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE }, |
| 109 | [M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, |
| 110 | [M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900, OVERRIDE_NONE }, |
| 111 | [M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200, OVERRIDE_NONE }, |
| 112 | [M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050, OVERRIDE_NONE }, |
| 113 | [M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800, OVERRIDE_NONE }, |
| 114 | [M_MBP_8_2] = { "mbp82", 0x90010000, 1472 * 4, 1440, 900, OVERRIDE_NONE }, |
| 115 | [M_UNKNOWN] = { NULL, 0, 0, 0, 0, OVERRIDE_NONE } |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static int set_system(const struct dmi_system_id *id); |
| 119 | |
| 120 | #define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \ |
| 121 | { set_system, name, { \ |
| 122 | DMI_MATCH(DMI_BIOS_VENDOR, vendor), \ |
| 123 | DMI_MATCH(DMI_PRODUCT_NAME, name) }, \ |
| 124 | &dmi_list[enumid] } |
| 125 | |
Henrik Kretzschmar | ec81c9c | 2010-08-10 18:02:28 -0700 | [diff] [blame] | 126 | static const struct dmi_system_id dmi_system_table[] __initconst = { |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 127 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17), |
| 128 | /* At least one of these two will be right; maybe both? */ |
| 129 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20), |
| 130 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20), |
| 131 | /* At least one of these two will be right; maybe both? */ |
| 132 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24), |
| 133 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24), |
| 134 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR), |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 135 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1), |
| 136 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1), |
| 137 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 138 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI), |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 139 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1), |
| 140 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 141 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB), |
| 142 | /* At least one of these two will be right; maybe both? */ |
| 143 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB), |
| 144 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB), |
| 145 | /* At least one of these two will be right; maybe both? */ |
| 146 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB), |
| 147 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB), |
| 148 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB), |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 149 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1), |
| 150 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1), |
| 151 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 152 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA), |
Matthew Garrett | 97fb850 | 2011-04-06 17:34:59 +0000 | [diff] [blame] | 153 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir3,1", M_MBA_3), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 154 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP), |
| 155 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2), |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 156 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 157 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2), |
| 158 | EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR), |
| 159 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR), |
| 160 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4), |
Thomas Gerlach | 8a3bdfe | 2010-04-23 13:17:50 -0400 | [diff] [blame] | 161 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1), |
Luke Macken | a5757c2 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 162 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2), |
| 163 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3), |
| 164 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1), |
| 165 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2), |
| 166 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1), |
Davidlohr Bueso | e9c5db0 | 2011-03-31 00:12:22 +0000 | [diff] [blame] | 167 | EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro8,2", M_MBP_8_2), |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 168 | {}, |
| 169 | }; |
| 170 | |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 171 | #define choose_value(dmivalue, fwvalue, field, flags) ({ \ |
| 172 | typeof(fwvalue) _ret_ = fwvalue; \ |
| 173 | if ((flags) & (field)) \ |
| 174 | _ret_ = dmivalue; \ |
| 175 | else if ((fwvalue) == 0) \ |
| 176 | _ret_ = dmivalue; \ |
| 177 | _ret_; \ |
| 178 | }) |
| 179 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 180 | static int set_system(const struct dmi_system_id *id) |
| 181 | { |
| 182 | struct efifb_dmi_info *info = id->driver_data; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 183 | |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 184 | if (info->base == 0 && info->height == 0 && info->width == 0 |
| 185 | && info->stride == 0) |
| 186 | return 0; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 187 | |
| 188 | /* Trust the bootloader over the DMI tables */ |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 189 | if (screen_info.lfb_base == 0) { |
| 190 | #if defined(CONFIG_PCI) |
| 191 | struct pci_dev *dev = NULL; |
| 192 | int found_bar = 0; |
| 193 | #endif |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 194 | if (info->base) { |
| 195 | screen_info.lfb_base = choose_value(info->base, |
| 196 | screen_info.lfb_base, OVERRIDE_BASE, |
| 197 | info->flags); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 198 | |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 199 | #if defined(CONFIG_PCI) |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 200 | /* make sure that the address in the table is actually |
| 201 | * on a VGA device's PCI BAR */ |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 202 | |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 203 | for_each_pci_dev(dev) { |
| 204 | int i; |
| 205 | if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 206 | continue; |
| 207 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 208 | resource_size_t start, end; |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 209 | |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 210 | start = pci_resource_start(dev, i); |
| 211 | if (start == 0) |
| 212 | break; |
| 213 | end = pci_resource_end(dev, i); |
| 214 | if (screen_info.lfb_base >= start && |
| 215 | screen_info.lfb_base < end) { |
| 216 | found_bar = 1; |
| 217 | } |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 220 | if (!found_bar) |
| 221 | screen_info.lfb_base = 0; |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 222 | #endif |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 223 | } |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 224 | } |
| 225 | if (screen_info.lfb_base) { |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 226 | screen_info.lfb_linelength = choose_value(info->stride, |
| 227 | screen_info.lfb_linelength, OVERRIDE_STRIDE, |
| 228 | info->flags); |
| 229 | screen_info.lfb_width = choose_value(info->width, |
| 230 | screen_info.lfb_width, OVERRIDE_WIDTH, |
| 231 | info->flags); |
| 232 | screen_info.lfb_height = choose_value(info->height, |
| 233 | screen_info.lfb_height, OVERRIDE_HEIGHT, |
| 234 | info->flags); |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 235 | if (screen_info.orig_video_isVGA == 0) |
| 236 | screen_info.orig_video_isVGA = VIDEO_TYPE_EFI; |
| 237 | } else { |
| 238 | screen_info.lfb_linelength = 0; |
| 239 | screen_info.lfb_width = 0; |
| 240 | screen_info.lfb_height = 0; |
| 241 | screen_info.orig_video_isVGA = 0; |
| 242 | return 0; |
| 243 | } |
Peter Jones | 47dfe51 | 2011-04-06 17:34:58 +0000 | [diff] [blame] | 244 | |
| 245 | printk(KERN_INFO "efifb: dmi detected %s - framebuffer at %p " |
| 246 | "(%dx%d, stride %d)\n", id->ident, |
| 247 | (void *)screen_info.lfb_base, screen_info.lfb_width, |
| 248 | screen_info.lfb_height, screen_info.lfb_linelength); |
| 249 | |
| 250 | |
Peter Jones | 85a00d9 | 2010-09-22 13:05:04 -0700 | [diff] [blame] | 251 | return 1; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 254 | static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 255 | unsigned blue, unsigned transp, |
| 256 | struct fb_info *info) |
| 257 | { |
| 258 | /* |
| 259 | * Set a single color register. The values supplied are |
| 260 | * already rounded down to the hardware's capabilities |
| 261 | * (according to the entries in the `var' structure). Return |
| 262 | * != 0 for invalid regno. |
| 263 | */ |
| 264 | |
| 265 | if (regno >= info->cmap.len) |
| 266 | return 1; |
| 267 | |
| 268 | if (regno < 16) { |
| 269 | red >>= 8; |
| 270 | green >>= 8; |
| 271 | blue >>= 8; |
| 272 | ((u32 *)(info->pseudo_palette))[regno] = |
| 273 | (red << info->var.red.offset) | |
| 274 | (green << info->var.green.offset) | |
| 275 | (blue << info->var.blue.offset); |
| 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 280 | static void efifb_destroy(struct fb_info *info) |
| 281 | { |
| 282 | if (info->screen_base) |
| 283 | iounmap(info->screen_base); |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 284 | release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 285 | framebuffer_release(info); |
| 286 | } |
| 287 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 288 | static struct fb_ops efifb_ops = { |
| 289 | .owner = THIS_MODULE, |
Marcin Slusarz | 89f3f21 | 2010-02-22 12:44:22 -0800 | [diff] [blame] | 290 | .fb_destroy = efifb_destroy, |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 291 | .fb_setcolreg = efifb_setcolreg, |
| 292 | .fb_fillrect = cfb_fillrect, |
| 293 | .fb_copyarea = cfb_copyarea, |
| 294 | .fb_imageblit = cfb_imageblit, |
| 295 | }; |
| 296 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 297 | static int __init efifb_setup(char *options) |
| 298 | { |
| 299 | char *this_opt; |
| 300 | int i; |
| 301 | |
| 302 | if (!options || !*options) |
| 303 | return 0; |
| 304 | |
| 305 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 306 | if (!*this_opt) continue; |
| 307 | |
| 308 | for (i = 0; i < M_UNKNOWN; i++) { |
| 309 | if (!strcmp(this_opt, dmi_list[i].optname) && |
| 310 | dmi_list[i].base != 0) { |
| 311 | screen_info.lfb_base = dmi_list[i].base; |
| 312 | screen_info.lfb_linelength = dmi_list[i].stride; |
| 313 | screen_info.lfb_width = dmi_list[i].width; |
| 314 | screen_info.lfb_height = dmi_list[i].height; |
| 315 | } |
| 316 | } |
| 317 | if (!strncmp(this_opt, "base:", 5)) |
| 318 | screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0); |
| 319 | else if (!strncmp(this_opt, "stride:", 7)) |
| 320 | screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4; |
| 321 | else if (!strncmp(this_opt, "height:", 7)) |
| 322 | screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0); |
| 323 | else if (!strncmp(this_opt, "width:", 6)) |
| 324 | screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0); |
| 325 | } |
| 326 | return 0; |
| 327 | } |
| 328 | |
Uwe Kleine-König | c2e1303 | 2010-02-04 20:56:51 +0100 | [diff] [blame] | 329 | static int __devinit efifb_probe(struct platform_device *dev) |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 330 | { |
| 331 | struct fb_info *info; |
| 332 | int err; |
| 333 | unsigned int size_vmode; |
| 334 | unsigned int size_remap; |
| 335 | unsigned int size_total; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 336 | int request_succeeded = 0; |
| 337 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 338 | if (!screen_info.lfb_depth) |
| 339 | screen_info.lfb_depth = 32; |
| 340 | if (!screen_info.pages) |
| 341 | screen_info.pages = 1; |
Matthew Garrett | 133bb07 | 2009-04-13 14:39:44 -0700 | [diff] [blame] | 342 | if (!screen_info.lfb_base) { |
| 343 | printk(KERN_DEBUG "efifb: invalid framebuffer address\n"); |
| 344 | return -ENODEV; |
| 345 | } |
| 346 | printk(KERN_INFO "efifb: probing for efifb\n"); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 347 | |
| 348 | /* just assume they're all unset if any are */ |
| 349 | if (!screen_info.blue_size) { |
| 350 | screen_info.blue_size = 8; |
| 351 | screen_info.blue_pos = 0; |
| 352 | screen_info.green_size = 8; |
| 353 | screen_info.green_pos = 8; |
| 354 | screen_info.red_size = 8; |
| 355 | screen_info.red_pos = 16; |
| 356 | screen_info.rsvd_size = 8; |
| 357 | screen_info.rsvd_pos = 24; |
| 358 | } |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 359 | |
| 360 | efifb_fix.smem_start = screen_info.lfb_base; |
| 361 | efifb_defined.bits_per_pixel = screen_info.lfb_depth; |
| 362 | efifb_defined.xres = screen_info.lfb_width; |
| 363 | efifb_defined.yres = screen_info.lfb_height; |
| 364 | efifb_fix.line_length = screen_info.lfb_linelength; |
| 365 | |
| 366 | /* size_vmode -- that is the amount of memory needed for the |
| 367 | * used video mode, i.e. the minimum amount of |
| 368 | * memory we need. */ |
| 369 | size_vmode = efifb_defined.yres * efifb_fix.line_length; |
| 370 | |
| 371 | /* size_total -- all video memory we have. Used for |
| 372 | * entries, ressource allocation and bounds |
| 373 | * checking. */ |
| 374 | size_total = screen_info.lfb_size; |
| 375 | if (size_total < size_vmode) |
| 376 | size_total = size_vmode; |
| 377 | |
| 378 | /* size_remap -- the amount of video memory we are going to |
| 379 | * use for efifb. With modern cards it is no |
| 380 | * option to simply use size_total as that |
| 381 | * wastes plenty of kernel address space. */ |
| 382 | size_remap = size_vmode * 2; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 383 | if (size_remap > size_total) |
| 384 | size_remap = size_total; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 385 | if (size_remap % PAGE_SIZE) |
| 386 | size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 387 | efifb_fix.smem_len = size_remap; |
| 388 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 389 | if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) { |
| 390 | request_succeeded = 1; |
| 391 | } else { |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 392 | /* We cannot make this fatal. Sometimes this comes from magic |
| 393 | spaces our resource handlers simply don't know about */ |
| 394 | printk(KERN_WARNING |
| 395 | "efifb: cannot reserve video memory at 0x%lx\n", |
| 396 | efifb_fix.smem_start); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 397 | } |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 398 | |
| 399 | info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev); |
| 400 | if (!info) { |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 401 | printk(KERN_ERR "efifb: cannot allocate framebuffer\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 402 | err = -ENOMEM; |
| 403 | goto err_release_mem; |
| 404 | } |
| 405 | info->pseudo_palette = info->par; |
| 406 | info->par = NULL; |
| 407 | |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 408 | info->apertures = alloc_apertures(1); |
| 409 | if (!info->apertures) { |
| 410 | err = -ENOMEM; |
| 411 | goto err_release_fb; |
| 412 | } |
| 413 | info->apertures->ranges[0].base = efifb_fix.smem_start; |
| 414 | info->apertures->ranges[0].size = size_remap; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 415 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 416 | info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len); |
| 417 | if (!info->screen_base) { |
| 418 | printk(KERN_ERR "efifb: abort, cannot ioremap video memory " |
| 419 | "0x%x @ 0x%lx\n", |
| 420 | efifb_fix.smem_len, efifb_fix.smem_start); |
| 421 | err = -EIO; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 422 | goto err_release_fb; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, " |
| 426 | "using %dk, total %dk\n", |
| 427 | efifb_fix.smem_start, info->screen_base, |
| 428 | size_remap/1024, size_total/1024); |
| 429 | printk(KERN_INFO "efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
| 430 | efifb_defined.xres, efifb_defined.yres, |
| 431 | efifb_defined.bits_per_pixel, efifb_fix.line_length, |
| 432 | screen_info.pages); |
| 433 | |
| 434 | efifb_defined.xres_virtual = efifb_defined.xres; |
| 435 | efifb_defined.yres_virtual = efifb_fix.smem_len / |
| 436 | efifb_fix.line_length; |
| 437 | printk(KERN_INFO "efifb: scrolling: redraw\n"); |
| 438 | efifb_defined.yres_virtual = efifb_defined.yres; |
| 439 | |
| 440 | /* some dummy values for timing to make fbset happy */ |
| 441 | efifb_defined.pixclock = 10000000 / efifb_defined.xres * |
| 442 | 1000 / efifb_defined.yres; |
| 443 | efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8; |
| 444 | efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8; |
| 445 | |
| 446 | efifb_defined.red.offset = screen_info.red_pos; |
| 447 | efifb_defined.red.length = screen_info.red_size; |
| 448 | efifb_defined.green.offset = screen_info.green_pos; |
| 449 | efifb_defined.green.length = screen_info.green_size; |
| 450 | efifb_defined.blue.offset = screen_info.blue_pos; |
| 451 | efifb_defined.blue.length = screen_info.blue_size; |
| 452 | efifb_defined.transp.offset = screen_info.rsvd_pos; |
| 453 | efifb_defined.transp.length = screen_info.rsvd_size; |
| 454 | |
| 455 | printk(KERN_INFO "efifb: %s: " |
| 456 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
| 457 | "Truecolor", |
| 458 | screen_info.rsvd_size, |
| 459 | screen_info.red_size, |
| 460 | screen_info.green_size, |
| 461 | screen_info.blue_size, |
| 462 | screen_info.rsvd_pos, |
| 463 | screen_info.red_pos, |
| 464 | screen_info.green_pos, |
| 465 | screen_info.blue_pos); |
| 466 | |
| 467 | efifb_fix.ypanstep = 0; |
| 468 | efifb_fix.ywrapstep = 0; |
| 469 | |
| 470 | info->fbops = &efifb_ops; |
| 471 | info->var = efifb_defined; |
| 472 | info->fix = efifb_fix; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 473 | info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 474 | |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 475 | if ((err = fb_alloc_cmap(&info->cmap, 256, 0)) < 0) { |
| 476 | printk(KERN_ERR "efifb: cannot allocate colormap\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 477 | goto err_unmap; |
| 478 | } |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 479 | if ((err = register_framebuffer(info)) < 0) { |
| 480 | printk(KERN_ERR "efifb: cannot register framebuffer\n"); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 481 | goto err_fb_dealoc; |
| 482 | } |
| 483 | printk(KERN_INFO "fb%d: %s frame buffer device\n", |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 484 | info->node, info->fix.id); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 485 | return 0; |
| 486 | |
| 487 | err_fb_dealoc: |
| 488 | fb_dealloc_cmap(&info->cmap); |
| 489 | err_unmap: |
| 490 | iounmap(info->screen_base); |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 491 | err_release_fb: |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 492 | framebuffer_release(info); |
| 493 | err_release_mem: |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 494 | if (request_succeeded) |
| 495 | release_mem_region(efifb_fix.smem_start, size_total); |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 496 | return err; |
| 497 | } |
| 498 | |
| 499 | static struct platform_driver efifb_driver = { |
| 500 | .probe = efifb_probe, |
| 501 | .driver = { |
| 502 | .name = "efifb", |
| 503 | }, |
| 504 | }; |
| 505 | |
| 506 | static struct platform_device efifb_device = { |
| 507 | .name = "efifb", |
| 508 | }; |
| 509 | |
| 510 | static int __init efifb_init(void) |
| 511 | { |
| 512 | int ret; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 513 | char *option = NULL; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 514 | |
Brian Maly | e14a685 | 2009-03-31 15:25:50 -0700 | [diff] [blame] | 515 | dmi_check_system(dmi_system_table); |
| 516 | |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 517 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) |
| 518 | return -ENODEV; |
Peter Jones | 7c08c9a | 2008-10-15 22:03:43 -0700 | [diff] [blame] | 519 | |
| 520 | if (fb_get_options("efifb", &option)) |
| 521 | return -ENODEV; |
| 522 | efifb_setup(option); |
| 523 | |
| 524 | /* We don't get linelength from UGA Draw Protocol, only from |
| 525 | * EFI Graphics Protocol. So if it's not in DMI, and it's not |
| 526 | * passed in from the user, we really can't use the framebuffer. |
| 527 | */ |
| 528 | if (!screen_info.lfb_linelength) |
| 529 | return -ENODEV; |
Huang, Ying | 7c83172 | 2007-11-28 16:21:55 -0800 | [diff] [blame] | 530 | |
| 531 | ret = platform_driver_register(&efifb_driver); |
| 532 | |
| 533 | if (!ret) { |
| 534 | ret = platform_device_register(&efifb_device); |
| 535 | if (ret) |
| 536 | platform_driver_unregister(&efifb_driver); |
| 537 | } |
| 538 | return ret; |
| 539 | } |
| 540 | module_init(efifb_init); |
| 541 | |
| 542 | MODULE_LICENSE("GPL"); |