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