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;
58 len = pci_biosrom_size(pdev);
59 rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
61 for (i = 0; i < len && rom; i += ISCI_ROM_SIG_SIZE) {
62 memcpy_fromio(rom->hdr.signature, oprom + i, ISCI_ROM_SIG_SIZE);
63 if (memcmp(rom->hdr.signature, ISCI_ROM_SIG,
64 ISCI_ROM_SIG_SIZE) == 0) {
65 size_t copy_len = min(len - i, sizeof(*rom));
67 memcpy_fromio(rom, oprom + i, copy_len);
73 dev_err(&pdev->dev, "oprom parse error\n");
74 devm_kfree(&pdev->dev, rom);
77 pci_unmap_biosrom(oprom);
83 * isci_parse_oem_parameters() - This method will take OEM parameters
84 * from the module init parameters and copy them to oem_params. This will
85 * only copy values that are not set to the module parameter default values
86 * @oem_parameters: This parameter specifies the controller default OEM
87 * parameters. It is expected that this has been initialized to the default
88 * parameters for the controller
92 enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
93 struct isci_orom *orom, int scu_index)
95 /* check for valid inputs */
96 if (scu_index < 0 || scu_index > SCI_MAX_CONTROLLERS ||
97 scu_index > orom->hdr.num_elements || !oem_params)
101 &orom->ctrl[scu_index],
102 sizeof(struct scic_sds_oem_params));
107 struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
109 struct isci_orom *orom = NULL, *data;
111 if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
114 if (fw->size < sizeof(*orom))
117 data = (struct isci_orom *)fw->data;
119 if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
120 strlen(ISCI_ROM_SIG)) != 0)
123 orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
127 memcpy(orom, fw->data, fw->size);
130 release_firmware(fw);
135 static struct efi *get_efi(void)
144 struct isci_orom *isci_get_efi_var(struct pci_dev *pdev)
146 struct efi_variable *evar;
148 struct isci_orom *orom = NULL;
150 evar = devm_kzalloc(&pdev->dev,
151 sizeof(struct efi_variable),
155 "Unable to allocate memory for EFI var\n");
159 evar->DataSize = 1024;
160 evar->VendorGuid = ISCI_EFI_VENDOR_GUID;
161 evar->Attributes = ISCI_EFI_ATTRIBUTES;
164 status = get_efi()->get_variable(evar->VariableName,
170 status = EFI_NOT_FOUND;
172 if (status == EFI_SUCCESS)
173 orom = (struct isci_orom *)evar->Data;
176 "Unable to obtain EFI variable for OEM parms\n");
178 if (orom && memcmp(orom->hdr.signature, ISCI_ROM_SIG,
179 strlen(ISCI_ROM_SIG)) != 0)
181 "Verifying OROM signature failed\n");
184 devm_kfree(&pdev->dev, evar);