|
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2 | + * * |
| 3 | + * Ghost, a micro-kernel based operating system for the x86 architecture * |
| 4 | + * Copyright (C) 2015, Max Schlüssel <[email protected]> * |
| 5 | + * * |
| 6 | + * This program is free software: you can redistribute it and/or modify * |
| 7 | + * it under the terms of the GNU General Public License as published by * |
| 8 | + * the Free Software Foundation, either version 3 of the License, or * |
| 9 | + * (at your option) any later version. * |
| 10 | + * * |
| 11 | + * This program is distributed in the hope that it will be useful, * |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | + * GNU General Public License for more details. * |
| 15 | + * * |
| 16 | + * You should have received a copy of the GNU General Public License * |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 18 | + * * |
| 19 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 20 | + |
| 21 | +#include "efifbdriver.hpp" |
| 22 | + |
| 23 | +#include <libdevice/manager.hpp> |
| 24 | +#include <ghost.h> |
| 25 | + |
| 26 | +#include <stdint.h> |
| 27 | +#include <string.h> |
| 28 | +#include <stdio.h> |
| 29 | + |
| 30 | +g_device_id deviceId; |
| 31 | + |
| 32 | +int main() |
| 33 | +{ |
| 34 | + g_task_register_name("efifbdriver"); |
| 35 | + |
| 36 | + if(!deviceManagerRegisterDevice(G_DEVICE_TYPE_VIDEO, g_get_tid(), &deviceId)) |
| 37 | + { |
| 38 | + klog("failed to register device with device manager"); |
| 39 | + return -1; |
| 40 | + } |
| 41 | + klog("registered EFI FB device %i", deviceId); |
| 42 | + |
| 43 | + efifbDriverReceiveMessages(); |
| 44 | + return 0; |
| 45 | +} |
| 46 | + |
| 47 | +void efifbDriverReceiveMessages() |
| 48 | +{ |
| 49 | + size_t buflen = sizeof(g_message_header) + 1024; |
| 50 | + uint8_t buf[buflen]; |
| 51 | + |
| 52 | + for(;;) |
| 53 | + { |
| 54 | + auto status = g_receive_message(buf, buflen); |
| 55 | + if(status != G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL) |
| 56 | + { |
| 57 | + continue; |
| 58 | + } |
| 59 | + |
| 60 | + g_message_header* header = (g_message_header*) buf; |
| 61 | + g_video_request_header* request = (g_video_request_header*) G_MESSAGE_CONTENT(buf); |
| 62 | + |
| 63 | + if(request->command == G_VIDEO_COMMAND_SET_MODE) |
| 64 | + { |
| 65 | + efifbDriverHandleCommandSetMode((g_video_set_mode_request*) request, header->sender, header->transaction); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + klog("efifbdriver: received unknown command %i from task %i", request->command, header->sender); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +void efifbDriverHandleCommandSetMode(g_video_set_mode_request* request, g_tid requestingTaskId, |
| 75 | + g_message_transaction requestTransaction) |
| 76 | +{ |
| 77 | + g_address lfb; |
| 78 | + uint16_t resX; |
| 79 | + uint16_t resY; |
| 80 | + uint16_t bpp; |
| 81 | + uint32_t pitch; |
| 82 | + g_get_efi_framebuffer(&lfb, &resX, &resY, &bpp, &pitch); |
| 83 | + |
| 84 | + uint64_t lfbSize = pitch * resY; |
| 85 | + auto localMapped = g_map_mmio((void*) lfb, lfbSize); |
| 86 | + // TODO: This is kind of unneccessary, we don't want to map it here |
| 87 | + void* addressInRequestersSpace = g_share_mem((void*) localMapped, lfbSize, requestingTaskId); |
| 88 | + |
| 89 | + g_video_set_mode_response response{}; |
| 90 | + response.status = G_VIDEO_SET_MODE_STATUS_SUCCESS; |
| 91 | + response.mode_info.lfb = (g_address) addressInRequestersSpace; |
| 92 | + response.mode_info.resX = resX; |
| 93 | + response.mode_info.resY = resY; |
| 94 | + response.mode_info.bpp = (uint8_t) bpp; |
| 95 | + response.mode_info.bpsl = (uint16_t) pitch; |
| 96 | + response.mode_info.explicit_update = false; |
| 97 | + g_send_message_t(requestingTaskId, &response, sizeof(g_video_set_mode_response), requestTransaction); |
| 98 | +} |
0 commit comments