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"
38 efi_char16_t VariableName[1024/sizeof(efi_char16_t)];
39 efi_guid_t VendorGuid;
40 unsigned long DataSize;
44 } __attribute__((packed));
46 struct isci_orom *isci_request_oprom(struct pci_dev *pdev)
48 void __iomem *oprom = pci_map_biosrom(pdev);
49 struct isci_orom *rom = NULL;
53 struct isci_oem_hdr oem_hdr;
59 len = pci_biosrom_size(pdev);
60 rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
63 "Unable to allocate memory for orom\n");
67 for (i = 0; i < len && rom; i += ISCI_OEM_SIG_SIZE) {
68 memcpy_fromio(oem_sig, oprom + i, ISCI_OEM_SIG_SIZE);
70 /* we think we found the OEM table */
71 if (memcmp(oem_sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) == 0) {
74 memcpy_fromio(&oem_hdr, oprom + i, sizeof(oem_hdr));
76 copy_len = min(oem_hdr.len - sizeof(oem_hdr),
80 oprom + i + sizeof(oem_hdr),
83 /* calculate checksum */
85 for (j = 0, sum = 0; j < sizeof(oem_hdr); j++, tmp++)
89 for (j = 0; j < sizeof(*rom); j++, tmp++)
94 "OEM table checksum failed\n");
98 /* keep going if that's not the oem param table */
99 if (memcmp(rom->hdr.signature,
101 ISCI_ROM_SIG_SIZE) != 0)
105 "OEM parameter table found in OROM\n");
111 dev_err(&pdev->dev, "oprom parse error\n");
112 devm_kfree(&pdev->dev, rom);
115 pci_unmap_biosrom(oprom);
121 * isci_parse_oem_parameters() - This method will take OEM parameters
122 * from the module init parameters and copy them to oem_params. This will
123 * only copy values that are not set to the module parameter default values
124 * @oem_parameters: This parameter specifies the controller default OEM
125 * parameters. It is expected that this has been initialized to the default
126 * parameters for the controller
130 enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
131 struct isci_orom *orom, int scu_index)
133 /* check for valid inputs */
134 if (scu_index < 0 || scu_index > SCI_MAX_CONTROLLERS ||
135 scu_index > orom->hdr.num_elements || !oem_params)
138 oem_params->sds1 = orom->ctrl[scu_index];
142 struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
144 struct isci_orom *orom = NULL, *data;
146 if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
149 if (fw->size < sizeof(*orom))
152 data = (struct isci_orom *)fw->data;
154 if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
155 strlen(ISCI_ROM_SIG)) != 0)
158 orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
162 memcpy(orom, fw->data, fw->size);
165 release_firmware(fw);
170 static struct efi *get_efi(void)
179 struct isci_orom *isci_get_efi_var(struct pci_dev *pdev)
181 struct efi_variable *evar;
183 struct isci_orom *rom = NULL;
184 struct isci_oem_hdr *oem_hdr;
189 evar = devm_kzalloc(&pdev->dev,
190 sizeof(struct efi_variable),
194 "Unable to allocate memory for EFI var\n");
198 rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
201 "Unable to allocate memory for orom\n");
205 for (j = 0; j < strlen(ISCI_EFI_VAR_NAME) + 1; j++)
206 evar->VariableName[j] = ISCI_EFI_VAR_NAME[j];
208 evar->DataSize = 1024;
209 evar->VendorGuid = ISCI_EFI_VENDOR_GUID;
210 evar->Attributes = ISCI_EFI_ATTRIBUTES;
213 status = get_efi()->get_variable(evar->VariableName,
219 status = EFI_NOT_FOUND;
221 if (status != EFI_SUCCESS) {
223 "Unable to obtain EFI variable for OEM parms\n");
227 oem_hdr = (struct isci_oem_hdr *)evar->Data;
229 if (memcmp(oem_hdr->sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) != 0) {
231 "Invalid OEM header signature\n");
235 /* calculate checksum */
237 for (j = 0, sum = 0; j < sizeof(oem_hdr); j++, tmp++)
241 for (j = 0; j < sizeof(*rom); j++, tmp++)
246 "OEM table checksum failed\n");
250 copy_len = min_t(u16, evar->DataSize,
251 min_t(u16, oem_hdr->len - sizeof(*oem_hdr), sizeof(*rom)));
253 memcpy(rom, (char *)evar->Data + sizeof(*oem_hdr), copy_len);
255 if (memcmp(rom->hdr.signature,
257 ISCI_ROM_SIG_SIZE) != 0) {
259 "Invalid OEM table signature\n");