1 | /*␊ |
2 | * Copyright (c) 2011,2012 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "bootstruct.h"␊ |
9 | #include "pci.h"␊ |
10 | #include "device_inject.h"␊ |
11 | #include "platform.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_SATA␊ |
14 | #define DEBUG_SATA 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_SATA␊ |
18 | #define DBG(x...) printf(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␊ |
21 | #endif␊ |
22 | ␉␊ |
23 | void SATA_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
24 | ␊ |
25 | uint8_t default_SATA_ID[]= {␊ |
26 | ␉0x81, 0x26, 0x00, 0x00␊ |
27 | };␊ |
28 | #define SATA_ID_LEN ( sizeof(default_SATA_ID) / sizeof(uint8_t) )␊ |
29 | ␊ |
30 | void SATA_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
31 | {␊ |
32 | ␉pci_dt_t* current = arg1;␊ |
33 | ␉struct DevPropDevice␉␉*device;␊ |
34 | ␉char␉␉␉␉␉␉*devicepath;␊ |
35 | struct DevPropString *string;␊ |
36 | ␉if (current && current->class_id == PCI_CLASS_STORAGE_SATA)␊ |
37 | ␉{␊ |
38 | ␉␉devicepath = get_pci_dev_path(current);␊ |
39 | ␉␉if (devicepath)␊ |
40 | ␉␉{␉␉␉␊ |
41 | ␊ |
42 | string = (struct DevPropString *)(uint32_t)get_env(envEFIString);␊ |
43 | ␊ |
44 | ␉␉␉if (!string)␊ |
45 | ␉␉␉{␊ |
46 | ␉␉␉␉string = devprop_create_string();␊ |
47 | if (!string) return;␊ |
48 | safe_set_env(envEFIString,(uint32_t)string);␊ |
49 | ␉␉␉}␊ |
50 | ␉␉␉device = devprop_add_device(string, devicepath);␊ |
51 | if (!device) return;␊ |
52 | ␊ |
53 | #if PROOFOFCONCEPT␊ |
54 | uint16_t vendor_id = current->vendor_id & 0xFFFF;␊ |
55 | uint16_t device_id = current->device_id & 0xFFFF;␊ |
56 | ␊ |
57 | ␉␉␉devprop_add_value(device, "vendor-id", (uint8_t*)&vendor_id, 4);␊ |
58 | ␉␉␉devprop_add_value(device, "device-id", (uint8_t*)&device_id, 4);␊ |
59 | #else␊ |
60 | devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN);␊ |
61 | ␊ |
62 | #endif ␊ |
63 | ␉␉␉verbose("SATA device : [%04x:%04x :: %04x] :: %s\n", ␊ |
64 | ␉␉␉␉␉current->vendor_id, current->device_id,current->class_id,␊ |
65 | ␉␉␉␉␉devicepath);␉␉␉␊ |
66 | ␉␉}␊ |
67 | ␉}␉␊ |
68 | ␉␊ |
69 | }␊ |
70 | ␊ |
71 | void YellowIconFixer_start(void);␊ |
72 | void YellowIconFixer_start(void)␊ |
73 | {␊ |
74 | register_hook_callback("PCIDevice", &SATA_hook);␊ |
75 | }␊ |
76 | ␊ |
77 | |