1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
/*
* $Id: ide_gen_cdrom.c,v 1.213 2009-11-24 14:22:19 vrsieh Exp $
*
* Copyright (C) 2007-2009 FAUmachine Team <info@faumachine.org>.
* This program is free software. You can redistribute it and/or modify it
* under the terms of the GNU General Public License, either version 2 of
* the License, or (at your option) any later version. See COPYING.
*/
/* This will turn on packet command debug output. */
#define DEBUGPCOM 0
/*
* Config Options
*/
#define CD_AUDIO_SUPPORT 0
#define CD_WRITER_SUPPORT 1
#define CD_CHANGER_SUPPORT 0
/* CD_WRITER_SUPPORT */
#define CD_WRITER_RW_SUPPORT 0
#define CD_WRITER_DAO_SUPPORT 1
#define CD_FORMAT_UNIT_SUPPORT 0
#define CD_READ_BUFFER_CAPACITY_SUPPORT 0
#define CD_READ_MASTER_CUE_SUPPORT 0
#define CD_SEND_CUE_SHEET_SUPPORT 0
#define CD_SEND_OPC_INFORMATION_SUPPORT 0
#define CD_PLAY_CD_SUPPORT 0
#define CD_READ_CD_SUPPORT 0
#define CD_SCAN_CD_SUPPORT 0
#define COMP ide_gen_cdrom
#define SCOMP "ide_gen_cdrom"
#include "config.h"
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "fixme.h"
#include "glue-log.h"
#include "glue-main.h"
#include "system.h"
#include "sig_ide.h"
#include "ide_gen_cdrom.h"
struct cpssp {
/* Config */
char name[1024];
/* Ports */
struct sig_boolean *port_power_power_5V;
struct sig_boolean *port_power_power_12V;
struct sig_magneto_optical *port_media;
struct sig_ide_bus *cable;
/* State */
unsigned char buf[0x10000];
unsigned int head;
unsigned int tail;
unsigned int count;
unsigned long m2t_count;
unsigned long long m2t_pos;
unsigned char error; /* error reg (ro) */
#define STATE
#define ATAPI 1
#define NAME cdrom
#define NAME_(x) cdrom_ ## x
#define SNAME "cdrom"
#include "arch_scsi_gen_cdrom.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef ATAPI
#define NAME atapi
#define NAME_(x) atapi_ ## x
#define SNAME "atapi"
#include "arch_gen_atapi.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef STATE
};
/*forward*/ static void
atapi_phase_free(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_cmd(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_status(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_data_in(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_data_out(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_msg_in(struct cpssp *cpssp);
/*forward*/ static void
atapi_phase_msg_out(struct cpssp *cpssp);
/*forward*/ static void
atapi_should_recv(struct cpssp *cpssp, unsigned long count);
/*forward*/ static void
atapi_should_send(struct cpssp *cpssp, unsigned long count);
/*forward*/ static void
cdrom_atn_set(struct cpssp *cpssp, unsigned int val);
/*forward*/ static int
cdrom_phase_select(struct cpssp *cpssp, uint32_t id);
/*forward*/ static int
cdrom_recv(struct cpssp *cpssp, uint8_t *buf, unsigned int bufsize);
/*forward*/ static int
cdrom_send(struct cpssp *cpssp, const uint8_t *buf, unsigned int bufsize);
static void
atapi_phase_select(struct cpssp *cpssp)
{
cdrom_atn_set(cpssp, 0);
(void) cdrom_phase_select(cpssp, 0);
}
static int
atapi_send(struct cpssp *cpssp, const void *buf, unsigned int bufsize)
{
return cdrom_send(cpssp, (const uint8_t *) buf, bufsize);
}
static int
atapi_recv(struct cpssp *cpssp, void *buf, unsigned int bufsize)
{
return cdrom_recv(cpssp, (uint8_t *) buf, bufsize);
}
static void
cdrom_want_recv(struct cpssp *cpssp, unsigned int count)
{
atapi_should_send(cpssp, count);
}
static void
cdrom_want_send(struct cpssp *cpssp, unsigned int count)
{
atapi_should_recv(cpssp, count);
}
static void
cdrom_phase_free(struct cpssp *cpssp)
{
atapi_phase_free(cpssp);
}
static void
cdrom_phase_cmd(struct cpssp *cpssp)
{
atapi_phase_cmd(cpssp);
}
static void
cdrom_phase_status(struct cpssp *cpssp)
{
atapi_phase_status(cpssp);
}
static void
cdrom_phase_data_in(struct cpssp *cpssp)
{
atapi_phase_data_in(cpssp);
}
static void
cdrom_phase_data_out(struct cpssp *cpssp)
{
atapi_phase_data_out(cpssp);
}
static void
cdrom_phase_msg_in(struct cpssp *cpssp)
{
atapi_phase_msg_in(cpssp);
}
static void
cdrom_phase_msg_out(struct cpssp *cpssp)
{
atapi_phase_msg_out(cpssp);
}
#define BEHAVIOR
#define ATAPI 1
#define NAME cdrom
#define NAME_(x) cdrom_ ## x
#define SNAME "cdrom"
#include "arch_scsi_gen_cdrom.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef ATAPI
#define NAME atapi
#define NAME_(x) atapi_ ## x
#define SNAME "atapi"
#include "arch_gen_atapi.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef BEHAVIOR
static void
ide_gen_cdrom_power_set(void *_cpssp, unsigned int val)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
atapi_power_set(cpssp, val);
cdrom_power_set(cpssp, val);
}
static int
ide_gen_cdrom_inw(void *_cpssp, unsigned short port, uint16_t *valp)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
return atapi_inw(cpssp, port, valp);
}
static void
ide_gen_cdrom_outw(void *_cpssp, unsigned short port, uint16_t value)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
atapi_outw(cpssp, port, value);
}
static void
ide_gen_cdrom_change(void *_cpssp, const char *path)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
cdrom_change(cpssp, path);
}
void *
ide_gen_cdrom_create(
const char *name,
const char *unit_str,
struct sig_manage *port_manage,
struct sig_power_device *port_power,
struct sig_ide_bus *port_ide,
struct sig_magneto_optical *port_media,
struct sig_string *port_change
)
{
static const struct sig_boolean_funcs power_funcs = {
.set = ide_gen_cdrom_power_set,
};
static const struct sig_ide_bus_device_funcs funcs = {
.inw = ide_gen_cdrom_inw,
.outw = ide_gen_cdrom_outw,
};
static const struct sig_string_funcs change_funcs = {
.set = ide_gen_cdrom_change,
};
struct cpssp *cpssp;
unsigned int unit;
char path[1024];
if (! unit_str) unit_str = "0";
system_name_push(name);
cpssp = malloc(sizeof(*cpssp));
assert(cpssp);
assert(strlen(system_path()) < sizeof(cpssp->name));
strcpy(cpssp->name, system_path());
unit = strtoul(unit_str, NULL, 0);
atapi_create(cpssp, unit);
assert(strlen(system_path()) + strlen(".media") + 1 <= sizeof(path));
sprintf(path, "%s.media", system_path());
cdrom_create(cpssp, path, 0);
cpssp->port_power_power_5V = port_power->power_5V;
cpssp->port_power_power_12V = port_power->power_12V;
sig_boolean_connect_in(cpssp->port_power_power_5V, cpssp, &power_funcs);
cpssp->cable = port_ide;
sig_ide_bus_connect_device(port_ide, cpssp, &funcs);
cpssp->port_media = port_media;
sig_string_connect(port_change, cpssp, &change_funcs);
system_name_pop();
return cpssp;
}
void
ide_gen_cdrom_destroy(void *_cpssp)
{
struct cpssp *cpssp = _cpssp;
atapi_destroy(cpssp);
cdrom_destroy(cpssp);
free(cpssp);
}
|