2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
25 /* probe_roms - scan for oem parameters */
27 #include <linux/kernel.h>
28 #include <linux/firmware.h>
29 #include <linux/uaccess.h>
30 #include <linux/efi.h>
31 #include <asm/probe_roms.h>
35 #include "probe_roms.h"
37 static efi_char16_t isci_efivar_name
[] = {
38 'R', 's', 't', 'S', 'c', 'u', 'O'
41 struct isci_orom
*isci_request_oprom(struct pci_dev
*pdev
)
43 void __iomem
*oprom
= pci_map_biosrom(pdev
);
44 struct isci_orom
*rom
= NULL
;
48 struct isci_oem_hdr oem_hdr
;
54 len
= pci_biosrom_size(pdev
);
55 rom
= devm_kzalloc(&pdev
->dev
, sizeof(*rom
), GFP_KERNEL
);
57 pci_unmap_biosrom(oprom
);
59 "Unable to allocate memory for orom\n");
63 for (i
= 0; i
< len
&& rom
; i
+= ISCI_OEM_SIG_SIZE
) {
64 memcpy_fromio(oem_sig
, oprom
+ i
, ISCI_OEM_SIG_SIZE
);
66 /* we think we found the OEM table */
67 if (memcmp(oem_sig
, ISCI_OEM_SIG
, ISCI_OEM_SIG_SIZE
) == 0) {
70 memcpy_fromio(&oem_hdr
, oprom
+ i
, sizeof(oem_hdr
));
72 copy_len
= min(oem_hdr
.len
- sizeof(oem_hdr
),
76 oprom
+ i
+ sizeof(oem_hdr
),
79 /* calculate checksum */
81 for (j
= 0, sum
= 0; j
< sizeof(oem_hdr
); j
++, tmp
++)
85 for (j
= 0; j
< sizeof(*rom
); j
++, tmp
++)
90 "OEM table checksum failed\n");
94 /* keep going if that's not the oem param table */
95 if (memcmp(rom
->hdr
.signature
,
97 ISCI_ROM_SIG_SIZE
) != 0)
101 "OEM parameter table found in OROM\n");
107 dev_err(&pdev
->dev
, "oprom parse error\n");
110 pci_unmap_biosrom(oprom
);
115 struct isci_orom
*isci_request_firmware(struct pci_dev
*pdev
, const struct firmware
*fw
)
117 struct isci_orom
*orom
= NULL
, *data
;
120 if (request_firmware(&fw
, ISCI_FW_NAME
, &pdev
->dev
) != 0)
123 if (fw
->size
< sizeof(*orom
))
126 data
= (struct isci_orom
*)fw
->data
;
128 if (strncmp(ISCI_ROM_SIG
, data
->hdr
.signature
,
129 strlen(ISCI_ROM_SIG
)) != 0)
132 orom
= devm_kzalloc(&pdev
->dev
, fw
->size
, GFP_KERNEL
);
136 memcpy(orom
, fw
->data
, fw
->size
);
138 if (is_c0(pdev
) || is_c1(pdev
))
142 * deprecated: override default amp_control for pre-preproduction
145 for (i
= 0; i
< ARRAY_SIZE(orom
->ctrl
); i
++)
146 for (j
= 0; j
< ARRAY_SIZE(orom
->ctrl
[i
].phys
); j
++) {
147 orom
->ctrl
[i
].phys
[j
].afe_tx_amp_control0
= 0xe7c03;
148 orom
->ctrl
[i
].phys
[j
].afe_tx_amp_control1
= 0xe7c03;
149 orom
->ctrl
[i
].phys
[j
].afe_tx_amp_control2
= 0xe7c03;
150 orom
->ctrl
[i
].phys
[j
].afe_tx_amp_control3
= 0xe7c03;
153 release_firmware(fw
);
158 static struct efi
*get_efi(void)
167 struct isci_orom
*isci_get_efi_var(struct pci_dev
*pdev
)
170 struct isci_orom
*rom
;
171 struct isci_oem_hdr
*oem_hdr
;
174 unsigned long data_len
;
179 efi_data
= devm_kzalloc(&pdev
->dev
, data_len
, GFP_KERNEL
);
182 "Unable to allocate memory for EFI data\n");
186 rom
= (struct isci_orom
*)(efi_data
+ sizeof(struct isci_oem_hdr
));
189 status
= get_efi()->get_variable(isci_efivar_name
,
190 &ISCI_EFI_VENDOR_GUID
,
195 status
= EFI_NOT_FOUND
;
197 if (status
!= EFI_SUCCESS
) {
199 "Unable to obtain EFI var data for OEM parms\n");
203 oem_hdr
= (struct isci_oem_hdr
*)efi_data
;
205 if (memcmp(oem_hdr
->sig
, ISCI_OEM_SIG
, ISCI_OEM_SIG_SIZE
) != 0) {
207 "Invalid OEM header signature\n");
211 /* calculate checksum */
212 tmp
= (u8
*)efi_data
;
213 for (j
= 0, sum
= 0; j
< (sizeof(*oem_hdr
) + sizeof(*rom
)); j
++, tmp
++)
218 "OEM table checksum failed\n");
222 if (memcmp(rom
->hdr
.signature
,
224 ISCI_ROM_SIG_SIZE
) != 0) {
226 "Invalid OEM table signature\n");