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 "sci_controller_constants.h"
36 #include "scic_remote_device.h"
37 #include "sci_environment.h"
38 #include "probe_roms.h"
41 efi_char16_t VariableName[1024/sizeof(efi_char16_t)];
42 efi_guid_t VendorGuid;
43 unsigned long DataSize;
47 } __attribute__((packed));
49 struct isci_orom *isci_request_oprom(struct pci_dev *pdev)
51 void __iomem *oprom = pci_map_biosrom(pdev);
52 struct isci_orom *rom = NULL;
56 struct isci_oem_hdr oem_hdr;
62 len = pci_biosrom_size(pdev);
63 rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
66 "Unable to allocate memory for orom\n");
70 for (i = 0; i < len && rom; i += ISCI_OEM_SIG_SIZE) {
71 memcpy_fromio(oem_sig, oprom + i, ISCI_OEM_SIG_SIZE);
73 /* we think we found the OEM table */
74 if (memcmp(oem_sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) == 0) {
77 memcpy_fromio(&oem_hdr, oprom + i, sizeof(oem_hdr));
79 copy_len = min(oem_hdr.len - sizeof(oem_hdr),
83 oprom + i + sizeof(oem_hdr),
86 /* calculate checksum */
88 for (j = 0, sum = 0; j < sizeof(oem_hdr); j++, tmp++)
92 for (j = 0; j < sizeof(*rom); j++, tmp++)
97 "OEM table checksum failed\n");
101 /* keep going if that's not the oem param table */
102 if (memcmp(rom->hdr.signature,
104 ISCI_ROM_SIG_SIZE) != 0)
108 "OEM parameter table found in OROM\n");
114 dev_err(&pdev->dev, "oprom parse error\n");
115 devm_kfree(&pdev->dev, rom);
118 pci_unmap_biosrom(oprom);
124 * isci_parse_oem_parameters() - This method will take OEM parameters
125 * from the module init parameters and copy them to oem_params. This will
126 * only copy values that are not set to the module parameter default values
127 * @oem_parameters: This parameter specifies the controller default OEM
128 * parameters. It is expected that this has been initialized to the default
129 * parameters for the controller
133 enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
134 struct isci_orom *orom, int scu_index)
136 /* check for valid inputs */
137 if (scu_index < 0 || scu_index > SCI_MAX_CONTROLLERS ||
138 scu_index > orom->hdr.num_elements || !oem_params)
141 oem_params->sds1 = orom->ctrl[scu_index];
145 struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
147 struct isci_orom *orom = NULL, *data;
149 if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
152 if (fw->size < sizeof(*orom))
155 data = (struct isci_orom *)fw->data;
157 if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
158 strlen(ISCI_ROM_SIG)) != 0)
161 orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
165 memcpy(orom, fw->data, fw->size);
168 release_firmware(fw);
173 static struct efi *get_efi(void)
182 struct isci_orom *isci_get_efi_var(struct pci_dev *pdev)
184 struct efi_variable *evar;
186 struct isci_orom *rom = NULL;
187 struct isci_oem_hdr *oem_hdr;
192 evar = devm_kzalloc(&pdev->dev,
193 sizeof(struct efi_variable),
197 "Unable to allocate memory for EFI var\n");
201 rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
204 "Unable to allocate memory for orom\n");
208 for (j = 0; j < strlen(ISCI_EFI_VAR_NAME) + 1; j++)
209 evar->VariableName[j] = ISCI_EFI_VAR_NAME[j];
211 evar->DataSize = 1024;
212 evar->VendorGuid = ISCI_EFI_VENDOR_GUID;
213 evar->Attributes = ISCI_EFI_ATTRIBUTES;
216 status = get_efi()->get_variable(evar->VariableName,
222 status = EFI_NOT_FOUND;
224 if (status != EFI_SUCCESS) {
226 "Unable to obtain EFI variable for OEM parms\n");
230 oem_hdr = (struct isci_oem_hdr *)evar->Data;
232 if (memcmp(oem_hdr->sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) != 0) {
234 "Invalid OEM header signature\n");
238 /* calculate checksum */
240 for (j = 0, sum = 0; j < sizeof(oem_hdr); j++, tmp++)
244 for (j = 0; j < sizeof(*rom); j++, tmp++)
249 "OEM table checksum failed\n");
253 copy_len = min(evar->DataSize,
254 min(oem_hdr->len - sizeof(*oem_hdr),
257 memcpy(rom, (char *)evar->Data + sizeof(*oem_hdr), copy_len);
259 if (memcmp(rom->hdr.signature,
261 ISCI_ROM_SIG_SIZE) != 0) {
263 "Invalid OEM table signature\n");