Commit | Line | Data |
---|---|---|
719f82d3 | 1 | /***********************************************************************/ |
95a4c6e7 | 2 | /** |
719f82d3 EB |
3 | |
4 | AudioScience HPI driver | |
95a4c6e7 | 5 | Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> |
719f82d3 EB |
6 | |
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of version 2 of the GNU General Public License as | |
9 | published by the Free Software Foundation; | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | ||
20 | \file | |
95a4c6e7 | 21 | Functions for reading DSP code using |
719f82d3 | 22 | hotplug firmware loader from individual dsp code files |
95a4c6e7 | 23 | */ |
719f82d3 EB |
24 | /***********************************************************************/ |
25 | #define SOURCEFILE_NAME "hpidspcd.c" | |
26 | #include "hpidspcd.h" | |
27 | #include "hpidebug.h" | |
28 | ||
95a4c6e7 EB |
29 | struct dsp_code_private { |
30 | /** Firmware descriptor */ | |
31 | const struct firmware *firmware; | |
32 | struct pci_dev *dev; | |
719f82d3 EB |
33 | }; |
34 | ||
719f82d3 EB |
35 | #define HPI_VER_DECIMAL ((int)(HPI_VER_MAJOR(HPI_VER) * 10000 + \ |
36 | HPI_VER_MINOR(HPI_VER) * 100 + HPI_VER_RELEASE(HPI_VER))) | |
37 | ||
719f82d3 | 38 | /*-------------------------------------------------------------------*/ |
95a4c6e7 EB |
39 | short hpi_dsp_code_open(u32 adapter, void *os_data, struct dsp_code *dsp_code, |
40 | u32 *os_error_code) | |
719f82d3 | 41 | { |
95a4c6e7 EB |
42 | const struct firmware *firmware; |
43 | struct pci_dev *dev = os_data; | |
719f82d3 EB |
44 | struct code_header header; |
45 | char fw_name[20]; | |
46 | int err; | |
47 | ||
48 | sprintf(fw_name, "asihpi/dsp%04x.bin", adapter); | |
719f82d3 | 49 | |
95a4c6e7 | 50 | err = request_firmware(&firmware, fw_name, &dev->dev); |
5ed15daf | 51 | |
95a4c6e7 EB |
52 | if (err || !firmware) { |
53 | dev_printk(KERN_ERR, &dev->dev, | |
5ed15daf EB |
54 | "%d, request_firmware failed for %s\n", err, |
55 | fw_name); | |
719f82d3 EB |
56 | goto error1; |
57 | } | |
95a4c6e7 EB |
58 | if (firmware->size < sizeof(header)) { |
59 | dev_printk(KERN_ERR, &dev->dev, "Header size too small %s\n", | |
60 | fw_name); | |
719f82d3 EB |
61 | goto error2; |
62 | } | |
95a4c6e7 EB |
63 | memcpy(&header, firmware->data, sizeof(header)); |
64 | ||
65 | if ((header.type != 0x45444F43) || /* "CODE" */ | |
66 | (header.adapter != adapter) | |
67 | || (header.size != firmware->size)) { | |
68 | dev_printk(KERN_ERR, &dev->dev, "Invalid firmware file\n"); | |
719f82d3 EB |
69 | goto error2; |
70 | } | |
71 | ||
95a4c6e7 EB |
72 | if ((header.version / 100 & ~1) != (HPI_VER_DECIMAL / 100 & ~1)) { |
73 | dev_printk(KERN_ERR, &dev->dev, | |
7f41b61b | 74 | "Incompatible firmware version " |
5ed15daf | 75 | "DSP image %d != Driver %d\n", header.version, |
719f82d3 EB |
76 | HPI_VER_DECIMAL); |
77 | goto error2; | |
78 | } | |
79 | ||
80 | if (header.version != HPI_VER_DECIMAL) { | |
95a4c6e7 | 81 | dev_printk(KERN_WARNING, &dev->dev, |
7f41b61b | 82 | "Firmware: release version mismatch DSP image %d != Driver %d\n", |
719f82d3 | 83 | header.version, HPI_VER_DECIMAL); |
719f82d3 EB |
84 | } |
85 | ||
5ed15daf | 86 | HPI_DEBUG_LOG(DEBUG, "dsp code %s opened\n", fw_name); |
95a4c6e7 EB |
87 | dsp_code->pvt = kmalloc(sizeof(*dsp_code->pvt), GFP_KERNEL); |
88 | if (!dsp_code->pvt) | |
89 | return HPI_ERROR_MEMORY_ALLOC; | |
90 | ||
91 | dsp_code->pvt->dev = dev; | |
92 | dsp_code->pvt->firmware = firmware; | |
93 | dsp_code->header = header; | |
94 | dsp_code->block_length = header.size / sizeof(u32); | |
95 | dsp_code->word_count = sizeof(header) / sizeof(u32); | |
719f82d3 EB |
96 | return 0; |
97 | ||
98 | error2: | |
95a4c6e7 | 99 | release_firmware(firmware); |
719f82d3 | 100 | error1: |
95a4c6e7 | 101 | dsp_code->block_length = 0; |
719f82d3 EB |
102 | return HPI_ERROR_DSP_FILE_NOT_FOUND; |
103 | } | |
104 | ||
105 | /*-------------------------------------------------------------------*/ | |
95a4c6e7 | 106 | void hpi_dsp_code_close(struct dsp_code *dsp_code) |
719f82d3 | 107 | { |
95a4c6e7 | 108 | if (dsp_code->pvt->firmware) { |
719f82d3 | 109 | HPI_DEBUG_LOG(DEBUG, "dsp code closed\n"); |
95a4c6e7 EB |
110 | release_firmware(dsp_code->pvt->firmware); |
111 | dsp_code->pvt->firmware = NULL; | |
719f82d3 | 112 | } |
95a4c6e7 | 113 | kfree(dsp_code->pvt); |
719f82d3 EB |
114 | } |
115 | ||
116 | /*-------------------------------------------------------------------*/ | |
95a4c6e7 | 117 | void hpi_dsp_code_rewind(struct dsp_code *dsp_code) |
719f82d3 EB |
118 | { |
119 | /* Go back to start of data, after header */ | |
95a4c6e7 | 120 | dsp_code->word_count = sizeof(struct code_header) / sizeof(u32); |
719f82d3 EB |
121 | } |
122 | ||
123 | /*-------------------------------------------------------------------*/ | |
95a4c6e7 | 124 | short hpi_dsp_code_read_word(struct dsp_code *dsp_code, u32 *pword) |
719f82d3 | 125 | { |
95a4c6e7 | 126 | if (dsp_code->word_count + 1 > dsp_code->block_length) |
5ed15daf | 127 | return HPI_ERROR_DSP_FILE_FORMAT; |
719f82d3 | 128 | |
95a4c6e7 | 129 | *pword = ((u32 *)(dsp_code->pvt->firmware->data))[dsp_code-> |
719f82d3 | 130 | word_count]; |
95a4c6e7 | 131 | dsp_code->word_count++; |
719f82d3 EB |
132 | return 0; |
133 | } | |
134 | ||
135 | /*-------------------------------------------------------------------*/ | |
136 | short hpi_dsp_code_read_block(size_t words_requested, | |
95a4c6e7 | 137 | struct dsp_code *dsp_code, u32 **ppblock) |
719f82d3 | 138 | { |
95a4c6e7 | 139 | if (dsp_code->word_count + words_requested > dsp_code->block_length) |
719f82d3 EB |
140 | return HPI_ERROR_DSP_FILE_FORMAT; |
141 | ||
142 | *ppblock = | |
95a4c6e7 EB |
143 | ((u32 *)(dsp_code->pvt->firmware->data)) + |
144 | dsp_code->word_count; | |
145 | dsp_code->word_count += words_requested; | |
719f82d3 EB |
146 | return 0; |
147 | } |