| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpigen.h> |
| 4 |
#include <cbfs.h> |
| 5 |
#include <mtcl.h> |
| 6 |
#include <stdint.h> |
| 7 |
#include <string.h> |
| 8 |
|
| 9 |
#define WIFI_MTCL_CBFS_DEFAULT_FILENAME "wifi_mtcl.bin" |
| 10 |
#define MAX_VERSION 2 |
| 11 |
#define MAX_SUPPORT_STATE 2 |
| 12 |
#define COUNTRY_LIST_SIZE 6 |
| 13 |
#define NAME_SIZE 4 |
| 14 |
#define MTCL_NAME "MTCL" |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
struct wifi_mtcl { |
| 25 |
uint8_t name[NAME_SIZE]; |
| 26 |
uint8_t revision; |
| 27 |
uint8_t support_6ghz; |
| 28 |
uint8_t country_list_6ghz[COUNTRY_LIST_SIZE]; |
| 29 |
uint8_t support_5p9ghz; |
| 30 |
uint8_t country_list_5p9ghz[COUNTRY_LIST_SIZE]; |
| 31 |
} __packed; |
| 32 |
|
| 33 |
void write_mtcl_aml(uint8_t *bytes, size_t count); |
| 34 |
int validate_mtcl(uint8_t *mtcl_bytes, size_t count); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
void write_mtcl_aml(uint8_t *bytes, size_t count) |
| 52 |
{ |
| 53 |
|
| 54 |
acpigen_write_method_serialized("MTCL", 0x0); |
| 55 |
|
| 56 |
|
| 57 |
acpigen_write_name("LIST"); |
| 58 |
|
| 59 |
|
| 60 |
acpigen_write_package(count); |
| 61 |
|
| 62 |
|
| 63 |
for (int i = 0; i < count; ++i) |
| 64 |
acpigen_write_byte(bytes[i]); |
| 65 |
|
| 66 |
acpigen_write_package_end(); |
| 67 |
|
| 68 |
|
| 69 |
acpigen_write_return_namestr("LIST"); |
| 70 |
acpigen_write_method_end(); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
int validate_mtcl(uint8_t *mtcl_bytes, size_t count) |
| 111 |
{ |
| 112 |
if (!mtcl_bytes) { |
| 113 |
printk(BIOS_ERR, "Failed to get the %s file size!\n", |
| 114 |
WIFI_MTCL_CBFS_DEFAULT_FILENAME); |
| 115 |
return -1; |
| 116 |
} |
| 117 |
|
| 118 |
if (count != sizeof(struct wifi_mtcl)) { |
| 119 |
printk(BIOS_ERR, "Size of file read was: %zu, expected: %zu\n", |
| 120 |
count, sizeof(struct wifi_mtcl)); |
| 121 |
return -1; |
| 122 |
} |
| 123 |
|
| 124 |
struct wifi_mtcl *mtcl = (struct wifi_mtcl *)mtcl_bytes; |
| 125 |
|
| 126 |
if (strncmp(((char *)mtcl->name), MTCL_NAME, NAME_SIZE)) { |
| 127 |
printk(BIOS_ERR, "MTCL string not present but expected\n"); |
| 128 |
return -1; |
| 129 |
} |
| 130 |
|
| 131 |
if (mtcl->revision > MAX_VERSION) { |
| 132 |
printk(BIOS_ERR, "MTCL version too high\n"); |
| 133 |
return -1; |
| 134 |
} |
| 135 |
|
| 136 |
if (mtcl->support_6ghz > MAX_SUPPORT_STATE) { |
| 137 |
printk(BIOS_ERR, "MTCL 6GHz support state too high\n"); |
| 138 |
return -1; |
| 139 |
} |
| 140 |
|
| 141 |
if (mtcl->support_5p9ghz > MAX_SUPPORT_STATE) { |
| 142 |
printk(BIOS_ERR, "MTCL 5.9GHz support state too high\n"); |
| 143 |
return -1; |
| 144 |
} |
| 145 |
|
| 146 |
return 0; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
void write_mtcl_function(void) |
| 156 |
{ |
| 157 |
size_t mtcl_bin_len; |
| 158 |
uint8_t *mtcl_bin; |
| 159 |
|
| 160 |
mtcl_bin = cbfs_map(WIFI_MTCL_CBFS_DEFAULT_FILENAME, &mtcl_bin_len); |
| 161 |
|
| 162 |
if (validate_mtcl(mtcl_bin, mtcl_bin_len) == 0) |
| 163 |
write_mtcl_aml(mtcl_bin, mtcl_bin_len); |
| 164 |
|
| 165 |
cbfs_unmap(mtcl_bin); |
| 166 |
} |