aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-01 17:09:21 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-01 17:09:21 -0500
commit455d80a9553915251b6392e31c39aeb8f8a94d68 (patch)
tree3b9452a3ee0d3a3de67f316f13bb6e3db00531fa
parent0ba11211f9ac583333aac44daec5af4f7eeba217 (diff)
ide-cd: remove struct atapi_capabilities_page (take 2)
* Remove struct atapi_capabilities_page. * Add ATAPI_CAPABILITIES_PAGE[_PAD]_SIZE define. v2: * The buf[] array access indexes were swapped between 'curspeed'/'maxspeed'. (Noticed by Borislav Petkov). Cc: Borislav Petkov <bbpetkov@yahoo.de> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
-rw-r--r--drivers/ide/ide-cd.c62
-rw-r--r--drivers/ide/ide-cd.h223
2 files changed, 37 insertions, 248 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 59981a043182..ab1cdce806ec 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2394,13 +2394,12 @@ int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock)
2394 return cdrom_lockdoor(drive, lock, NULL); 2394 return cdrom_lockdoor(drive, lock, NULL);
2395} 2395}
2396 2396
2397static 2397static int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
2398int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_page *cap)
2399{ 2398{
2400 struct cdrom_info *info = drive->driver_data; 2399 struct cdrom_info *info = drive->driver_data;
2401 struct cdrom_device_info *cdi = &info->devinfo; 2400 struct cdrom_device_info *cdi = &info->devinfo;
2402 struct packet_command cgc; 2401 struct packet_command cgc;
2403 int stat, attempts = 3, size = sizeof(*cap); 2402 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
2404 2403
2405 /* 2404 /*
2406 * ACER50 (and others?) require the full spec length mode sense 2405 * ACER50 (and others?) require the full spec length mode sense
@@ -2408,9 +2407,9 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_pag
2408 */ 2407 */
2409 if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") || 2408 if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") ||
2410 !strcmp(drive->id->model, "WPI CDS-32X"))) 2409 !strcmp(drive->id->model, "WPI CDS-32X")))
2411 size -= sizeof(cap->pad); 2410 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
2412 2411
2413 init_cdrom_command(&cgc, cap, size, CGC_DATA_UNKNOWN); 2412 init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN);
2414 do { /* we seem to get stat=0x01,err=0x00 the first time (??) */ 2413 do { /* we seem to get stat=0x01,err=0x00 the first time (??) */
2415 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); 2414 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
2416 if (!stat) 2415 if (!stat)
@@ -2419,20 +2418,22 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_pag
2419 return stat; 2418 return stat;
2420} 2419}
2421 2420
2422static 2421static void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
2423void ide_cdrom_update_speed (ide_drive_t *drive, struct atapi_capabilities_page *cap)
2424{ 2422{
2425 struct cdrom_info *cd = drive->driver_data; 2423 struct cdrom_info *cd = drive->driver_data;
2426 u16 curspeed, maxspeed; 2424 u16 curspeed, maxspeed;
2427 2425
2426 curspeed = *(u16 *)&buf[8 + 14];
2427 maxspeed = *(u16 *)&buf[8 + 8];
2428
2428 /* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */ 2429 /* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */
2429 if (!drive->id->model[0] && 2430 if (!drive->id->model[0] &&
2430 !strncmp(drive->id->fw_rev, "241N", 4)) { 2431 !strncmp(drive->id->fw_rev, "241N", 4)) {
2431 curspeed = le16_to_cpu(cap->curspeed); 2432 curspeed = le16_to_cpu(curspeed);
2432 maxspeed = le16_to_cpu(cap->maxspeed); 2433 maxspeed = le16_to_cpu(maxspeed);
2433 } else { 2434 } else {
2434 curspeed = be16_to_cpu(cap->curspeed); 2435 curspeed = be16_to_cpu(curspeed);
2435 maxspeed = be16_to_cpu(cap->maxspeed); 2436 maxspeed = be16_to_cpu(maxspeed);
2436 } 2437 }
2437 2438
2438 cd->state_flags.current_speed = (curspeed + (176/2)) / 176; 2439 cd->state_flags.current_speed = (curspeed + (176/2)) / 176;
@@ -2445,14 +2446,14 @@ int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed)
2445 ide_drive_t *drive = cdi->handle; 2446 ide_drive_t *drive = cdi->handle;
2446 struct cdrom_info *cd = drive->driver_data; 2447 struct cdrom_info *cd = drive->driver_data;
2447 struct request_sense sense; 2448 struct request_sense sense;
2448 struct atapi_capabilities_page cap; 2449 u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
2449 int stat; 2450 int stat;
2450 2451
2451 if ((stat = cdrom_select_speed(drive, speed, &sense)) < 0) 2452 if ((stat = cdrom_select_speed(drive, speed, &sense)) < 0)
2452 return stat; 2453 return stat;
2453 2454
2454 if (!ide_cdrom_get_capabilities(drive, &cap)) { 2455 if (!ide_cdrom_get_capabilities(drive, buf)) {
2455 ide_cdrom_update_speed(drive, &cap); 2456 ide_cdrom_update_speed(drive, buf);
2456 cdi->speed = cd->state_flags.current_speed; 2457 cdi->speed = cd->state_flags.current_speed;
2457 } 2458 }
2458 return 0; 2459 return 0;
@@ -2636,7 +2637,8 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2636{ 2637{
2637 struct cdrom_info *cd = drive->driver_data; 2638 struct cdrom_info *cd = drive->driver_data;
2638 struct cdrom_device_info *cdi = &cd->devinfo; 2639 struct cdrom_device_info *cdi = &cd->devinfo;
2639 struct atapi_capabilities_page cap; 2640 u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE];
2641 mechtype_t mechtype;
2640 int nslots = 1; 2642 int nslots = 1;
2641 2643
2642 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | 2644 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
@@ -2666,26 +2668,28 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2666 cdi->handle = drive; 2668 cdi->handle = drive;
2667 cdi->ops = &ide_cdrom_dops; 2669 cdi->ops = &ide_cdrom_dops;
2668 2670
2669 if (ide_cdrom_get_capabilities(drive, &cap)) 2671 if (ide_cdrom_get_capabilities(drive, buf))
2670 return 0; 2672 return 0;
2671 2673
2672 if (cap.lock == 0) 2674 if ((buf[8 + 6] & 0x01) == 0)
2673 cd->config_flags.no_doorlock = 1; 2675 cd->config_flags.no_doorlock = 1;
2674 if (cap.eject) 2676 if (buf[8 + 6] & 0x08)
2675 cd->config_flags.no_eject = 0; 2677 cd->config_flags.no_eject = 0;
2676 if (cap.cd_r_write) 2678 if (buf[8 + 3] & 0x01)
2677 cdi->mask &= ~CDC_CD_R; 2679 cdi->mask &= ~CDC_CD_R;
2678 if (cap.cd_rw_write) 2680 if (buf[8 + 3] & 0x02)
2679 cdi->mask &= ~(CDC_CD_RW | CDC_RAM); 2681 cdi->mask &= ~(CDC_CD_RW | CDC_RAM);
2680 if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom) 2682 if (buf[8 + 2] & 0x38)
2681 cdi->mask &= ~CDC_DVD; 2683 cdi->mask &= ~CDC_DVD;
2682 if (cap.dvd_ram_write) 2684 if (buf[8 + 3] & 0x20)
2683 cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM); 2685 cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM);
2684 if (cap.dvd_r_write) 2686 if (buf[8 + 3] & 0x10)
2685 cdi->mask &= ~CDC_DVD_R; 2687 cdi->mask &= ~CDC_DVD_R;
2686 if (cap.audio_play) 2688 if (buf[8 + 4] & 0x01)
2687 cdi->mask &= ~CDC_PLAY_AUDIO; 2689 cdi->mask &= ~CDC_PLAY_AUDIO;
2688 if (cap.mechtype == mechtype_caddy || cap.mechtype == mechtype_popup) 2690
2691 mechtype = buf[8 + 6] >> 5;
2692 if (mechtype == mechtype_caddy || mechtype == mechtype_popup)
2689 cdi->mask |= CDC_CLOSE_TRAY; 2693 cdi->mask |= CDC_CLOSE_TRAY;
2690 2694
2691 /* Some drives used by Apple don't advertise audio play 2695 /* Some drives used by Apple don't advertise audio play
@@ -2705,14 +2709,14 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2705 2709
2706 else 2710 else
2707#endif /* not STANDARD_ATAPI */ 2711#endif /* not STANDARD_ATAPI */
2708 if (cap.mechtype == mechtype_individual_changer || 2712 if (mechtype == mechtype_individual_changer ||
2709 cap.mechtype == mechtype_cartridge_changer) { 2713 mechtype == mechtype_cartridge_changer) {
2710 nslots = cdrom_number_of_slots(cdi); 2714 nslots = cdrom_number_of_slots(cdi);
2711 if (nslots > 1) 2715 if (nslots > 1)
2712 cdi->mask &= ~CDC_SELECT_DISC; 2716 cdi->mask &= ~CDC_SELECT_DISC;
2713 } 2717 }
2714 2718
2715 ide_cdrom_update_speed(drive, &cap); 2719 ide_cdrom_update_speed(drive, buf);
2716 2720
2717 printk(KERN_INFO "%s: ATAPI", drive->name); 2721 printk(KERN_INFO "%s: ATAPI", drive->name);
2718 2722
@@ -2737,7 +2741,7 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2737 else 2741 else
2738 printk(KERN_CONT " drive"); 2742 printk(KERN_CONT " drive");
2739 2743
2740 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpu(cap.buffer_size)); 2744 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpu(*(u16 *)&buf[8 + 12]));
2741 2745
2742 return nslots; 2746 return nslots;
2743} 2747}
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 8dbe346b4b44..9d88b1a7ffe5 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -50,6 +50,10 @@
50#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS) 50#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS)
51#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32) 51#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)
52 52
53/* Capabilities Page size including 8 bytes of Mode Page Header */
54#define ATAPI_CAPABILITIES_PAGE_SIZE (8 + 20)
55#define ATAPI_CAPABILITIES_PAGE_PAD_SIZE 4
56
53/* Configuration flags. These describe the capabilities of the drive. 57/* Configuration flags. These describe the capabilities of the drive.
54 They generally do not change after initialization, unless we learn 58 They generally do not change after initialization, unless we learn
55 more about the drive from stuff failing. */ 59 more about the drive from stuff failing. */
@@ -124,225 +128,6 @@ struct atapi_toc {
124 /* One extra for the leadout. */ 128 /* One extra for the leadout. */
125}; 129};
126 130
127/* This should probably go into cdrom.h along with the other
128 * generic stuff now in the Mt. Fuji spec.
129 */
130struct atapi_capabilities_page {
131 struct mode_page_header header;
132#if defined(__BIG_ENDIAN_BITFIELD)
133 __u8 parameters_saveable : 1;
134 __u8 reserved1 : 1;
135 __u8 page_code : 6;
136#elif defined(__LITTLE_ENDIAN_BITFIELD)
137 __u8 page_code : 6;
138 __u8 reserved1 : 1;
139 __u8 parameters_saveable : 1;
140#else
141#error "Please fix <asm/byteorder.h>"
142#endif
143
144 byte page_length;
145
146#if defined(__BIG_ENDIAN_BITFIELD)
147 __u8 reserved2 : 2;
148 /* Drive supports reading of DVD-RAM discs */
149 __u8 dvd_ram_read : 1;
150 /* Drive supports reading of DVD-R discs */
151 __u8 dvd_r_read : 1;
152 /* Drive supports reading of DVD-ROM discs */
153 __u8 dvd_rom : 1;
154 /* Drive supports reading CD-R discs with addressing method 2 */
155 __u8 method2 : 1; /* reserved in 1.2 */
156 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
157 __u8 cd_rw_read : 1; /* reserved in 1.2 */
158 /* Drive supports read from CD-R discs (orange book, part II) */
159 __u8 cd_r_read : 1; /* reserved in 1.2 */
160#elif defined(__LITTLE_ENDIAN_BITFIELD)
161 /* Drive supports read from CD-R discs (orange book, part II) */
162 __u8 cd_r_read : 1; /* reserved in 1.2 */
163 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
164 __u8 cd_rw_read : 1; /* reserved in 1.2 */
165 /* Drive supports reading CD-R discs with addressing method 2 */
166 __u8 method2 : 1;
167 /* Drive supports reading of DVD-ROM discs */
168 __u8 dvd_rom : 1;
169 /* Drive supports reading of DVD-R discs */
170 __u8 dvd_r_read : 1;
171 /* Drive supports reading of DVD-RAM discs */
172 __u8 dvd_ram_read : 1;
173 __u8 reserved2 : 2;
174#else
175#error "Please fix <asm/byteorder.h>"
176#endif
177
178#if defined(__BIG_ENDIAN_BITFIELD)
179 __u8 reserved3 : 2;
180 /* Drive can write DVD-RAM discs */
181 __u8 dvd_ram_write : 1;
182 /* Drive can write DVD-R discs */
183 __u8 dvd_r_write : 1;
184 __u8 reserved3a : 1;
185 /* Drive can fake writes */
186 __u8 test_write : 1;
187 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
188 __u8 cd_rw_write : 1; /* reserved in 1.2 */
189 /* Drive supports write to CD-R discs (orange book, part II) */
190 __u8 cd_r_write : 1; /* reserved in 1.2 */
191#elif defined(__LITTLE_ENDIAN_BITFIELD)
192 /* Drive can write to CD-R discs (orange book, part II) */
193 __u8 cd_r_write : 1; /* reserved in 1.2 */
194 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
195 __u8 cd_rw_write : 1; /* reserved in 1.2 */
196 /* Drive can fake writes */
197 __u8 test_write : 1;
198 __u8 reserved3a : 1;
199 /* Drive can write DVD-R discs */
200 __u8 dvd_r_write : 1;
201 /* Drive can write DVD-RAM discs */
202 __u8 dvd_ram_write : 1;
203 __u8 reserved3 : 2;
204#else
205#error "Please fix <asm/byteorder.h>"
206#endif
207
208#if defined(__BIG_ENDIAN_BITFIELD)
209 __u8 reserved4 : 1;
210 /* Drive can read multisession discs. */
211 __u8 multisession : 1;
212 /* Drive can read mode 2, form 2 data. */
213 __u8 mode2_form2 : 1;
214 /* Drive can read mode 2, form 1 (XA) data. */
215 __u8 mode2_form1 : 1;
216 /* Drive supports digital output on port 2. */
217 __u8 digport2 : 1;
218 /* Drive supports digital output on port 1. */
219 __u8 digport1 : 1;
220 /* Drive can deliver a composite audio/video data stream. */
221 __u8 composite : 1;
222 /* Drive supports audio play operations. */
223 __u8 audio_play : 1;
224#elif defined(__LITTLE_ENDIAN_BITFIELD)
225 /* Drive supports audio play operations. */
226 __u8 audio_play : 1;
227 /* Drive can deliver a composite audio/video data stream. */
228 __u8 composite : 1;
229 /* Drive supports digital output on port 1. */
230 __u8 digport1 : 1;
231 /* Drive supports digital output on port 2. */
232 __u8 digport2 : 1;
233 /* Drive can read mode 2, form 1 (XA) data. */
234 __u8 mode2_form1 : 1;
235 /* Drive can read mode 2, form 2 data. */
236 __u8 mode2_form2 : 1;
237 /* Drive can read multisession discs. */
238 __u8 multisession : 1;
239 __u8 reserved4 : 1;
240#else
241#error "Please fix <asm/byteorder.h>"
242#endif
243
244#if defined(__BIG_ENDIAN_BITFIELD)
245 __u8 reserved5 : 1;
246 /* Drive can return Media Catalog Number (UPC) info. */
247 __u8 upc : 1;
248 /* Drive can return International Standard Recording Code info. */
249 __u8 isrc : 1;
250 /* Drive supports C2 error pointers. */
251 __u8 c2_pointers : 1;
252 /* R-W data will be returned deinterleaved and error corrected. */
253 __u8 rw_corr : 1;
254 /* Subchannel reads can return combined R-W information. */
255 __u8 rw_supported : 1;
256 /* Drive can continue a read cdda operation from a loss of streaming.*/
257 __u8 cdda_accurate : 1;
258 /* Drive can read Red Book audio data. */
259 __u8 cdda : 1;
260#elif defined(__LITTLE_ENDIAN_BITFIELD)
261 /* Drive can read Red Book audio data. */
262 __u8 cdda : 1;
263 /* Drive can continue a read cdda operation from a loss of streaming.*/
264 __u8 cdda_accurate : 1;
265 /* Subchannel reads can return combined R-W information. */
266 __u8 rw_supported : 1;
267 /* R-W data will be returned deinterleaved and error corrected. */
268 __u8 rw_corr : 1;
269 /* Drive supports C2 error pointers. */
270 __u8 c2_pointers : 1;
271 /* Drive can return International Standard Recording Code info. */
272 __u8 isrc : 1;
273 /* Drive can return Media Catalog Number (UPC) info. */
274 __u8 upc : 1;
275 __u8 reserved5 : 1;
276#else
277#error "Please fix <asm/byteorder.h>"
278#endif
279
280#if defined(__BIG_ENDIAN_BITFIELD)
281 /* Drive mechanism types. */
282 mechtype_t mechtype : 3;
283 __u8 reserved6 : 1;
284 /* Drive can eject a disc or changer cartridge. */
285 __u8 eject : 1;
286 /* State of prevent/allow jumper. */
287 __u8 prevent_jumper : 1;
288 /* Present state of door lock. */
289 __u8 lock_state : 1;
290 /* Drive can lock the door. */
291 __u8 lock : 1;
292#elif defined(__LITTLE_ENDIAN_BITFIELD)
293
294 /* Drive can lock the door. */
295 __u8 lock : 1;
296 /* Present state of door lock. */
297 __u8 lock_state : 1;
298 /* State of prevent/allow jumper. */
299 __u8 prevent_jumper : 1;
300 /* Drive can eject a disc or changer cartridge. */
301 __u8 eject : 1;
302 __u8 reserved6 : 1;
303 /* Drive mechanism types. */
304 mechtype_t mechtype : 3;
305#else
306#error "Please fix <asm/byteorder.h>"
307#endif
308
309#if defined(__BIG_ENDIAN_BITFIELD)
310 __u8 reserved7 : 4;
311 /* Drive supports software slot selection. */
312 __u8 sss : 1; /* reserved in 1.2 */
313 /* Changer can report exact contents of slots. */
314 __u8 disc_present : 1; /* reserved in 1.2 */
315 /* Audio for each channel can be muted independently. */
316 __u8 separate_mute : 1;
317 /* Audio level for each channel can be controlled independently. */
318 __u8 separate_volume : 1;
319#elif defined(__LITTLE_ENDIAN_BITFIELD)
320
321 /* Audio level for each channel can be controlled independently. */
322 __u8 separate_volume : 1;
323 /* Audio for each channel can be muted independently. */
324 __u8 separate_mute : 1;
325 /* Changer can report exact contents of slots. */
326 __u8 disc_present : 1; /* reserved in 1.2 */
327 /* Drive supports software slot selection. */
328 __u8 sss : 1; /* reserved in 1.2 */
329 __u8 reserved7 : 4;
330#else
331#error "Please fix <asm/byteorder.h>"
332#endif
333
334 /* Note: the following four fields are returned in big-endian form. */
335 /* Maximum speed (in kB/s). */
336 unsigned short maxspeed;
337 /* Number of discrete volume levels. */
338 unsigned short n_vol_levels;
339 /* Size of cache in drive, in kB. */
340 unsigned short buffer_size;
341 /* Current speed (in kB/s). */
342 unsigned short curspeed;
343 char pad[4];
344};
345
346/* Extra per-device info for cdrom drives. */ 131/* Extra per-device info for cdrom drives. */
347struct cdrom_info { 132struct cdrom_info {
348 ide_drive_t *drive; 133 ide_drive_t *drive;