1 | /*␊ |
2 | * Copyright (c) 2011 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "boot.h"␊ |
9 | #include "bootstruct.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "device_inject.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 | #define kEnableSATA␉"EnableSATAModule"␊ |
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 | ␉if (current && current->class_id == PCI_CLASS_STORAGE_SATA)␊ |
36 | ␉{␊ |
37 | ␉␉devicepath = get_pci_dev_path(current);␊ |
38 | ␉␉if (devicepath[0] != 0)␊ |
39 | ␉␉{␊ |
40 | ␉␉␉verbose("SATA device : [%04x:%04x :: %04x] :: %s\n", ␊ |
41 | ␉␉␉␉␉current->vendor_id, current->device_id,current->class_id,␊ |
42 | ␉␉␉␉␉devicepath);␊ |
43 | ␉␉␉␊ |
44 | ␉␉␉if (!string)␊ |
45 | ␉␉␉{␊ |
46 | ␉␉␉␉string = devprop_create_string();␊ |
47 | ␉␉␉}␊ |
48 | ␉␉␉device = devprop_add_device(string, devicepath);␊ |
49 | ␉␉␉␊ |
50 | ␉␉␉devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN);␊ |
51 | ␉␉␉␉␉␉␊ |
52 | ␉␉␉␊ |
53 | ␉␉␉stringdata = malloc(sizeof(uint8_t) * string->length);␊ |
54 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
55 | ␉␉␉stringlength = string->length;␊ |
56 | ␉␉␉␊ |
57 | ␉␉}␊ |
58 | ␉}␉␊ |
59 | ␉␊ |
60 | }␊ |
61 | ␊ |
62 | void YellowIconFixer_start()␊ |
63 | {␊ |
64 | ␉bool enable = true;␊ |
65 | ␉getBoolForKey(kEnableSATA, &enable, &bootInfo->bootConfig) ;␊ |
66 | ␉␊ |
67 | ␉if (enable)␊ |
68 | ␉{␊ |
69 | ␉␉register_hook_callback("PCIDevice", &SATA_hook);␊ |
70 | ␉}␊ |
71 | }␊ |
72 | ␊ |
73 | |