Deleted Added
full compact
scd.c (24203) scd.c (25056)
1/*-
2 * Copyright (c) 1995 Mikael Hybsch
3 * All rights reserved.
4 *
5 * Portions of this file are copied from mcd.c
6 * which has the following copyrights:
7 *
8 * Copyright 1993 by Holger Veit (data part)

--- 27 unchanged lines hidden (view full) ---

36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 */
42
43
1/*-
2 * Copyright (c) 1995 Mikael Hybsch
3 * All rights reserved.
4 *
5 * Portions of this file are copied from mcd.c
6 * which has the following copyrights:
7 *
8 * Copyright 1993 by Holger Veit (data part)

--- 27 unchanged lines hidden (view full) ---

36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 */
42
43
44/* $Id: scd.c,v 1.27 1997/02/22 09:37:03 peter Exp $ */
44/* $Id: scd.c,v 1.28 1997/03/24 11:24:01 bde Exp $ */
45
46/* Please send any comments to micke@dynas.se */
47
48#define SCD_DEBUG 0
49
50#include "scd.h"
51#if NSCD > 0
52#include <sys/types.h>

--- 106 unchanged lines hidden (view full) ---

159static int send_cmd(u_int unit, u_char cmd, u_int nargs, ...);
160static void init_drive(unsigned unit);
161static int spin_up(unsigned unit);
162static int read_toc(dev_t dev);
163static int get_result(u_int unit, int result_len, u_char *result);
164static void print_error(int unit, int errcode);
165
166static void scd_start(int unit);
45
46/* Please send any comments to micke@dynas.se */
47
48#define SCD_DEBUG 0
49
50#include "scd.h"
51#if NSCD > 0
52#include <sys/types.h>

--- 106 unchanged lines hidden (view full) ---

159static int send_cmd(u_int unit, u_char cmd, u_int nargs, ...);
160static void init_drive(unsigned unit);
161static int spin_up(unsigned unit);
162static int read_toc(dev_t dev);
163static int get_result(u_int unit, int result_len, u_char *result);
164static void print_error(int unit, int errcode);
165
166static void scd_start(int unit);
167static timeout_t scd_timeout;
167static void scd_doread(int state, struct scd_mbx *mbxin);
168
169static int scd_eject(int unit);
170static int scd_stop(int unit);
171static int scd_pause(int unit);
172static int scd_resume(int unit);
173static int scd_playtracks(int unit, struct ioc_play_track *pt);
174static int scd_playmsf(int unit, struct ioc_play_msf *msf);

--- 597 unchanged lines hidden (view full) ---

772 * SCD_S_WAITFIFO: wait for param fifo to get ready, them exec. command.
773 * SCD_S_WAITREAD: wait for data ready, read data
774 * SCD_S_WAITPARAM: wait for command result params, read them, error if bad data read.
775 */
776
777static struct scd_mbx *mbxsave;
778
779static void
168static void scd_doread(int state, struct scd_mbx *mbxin);
169
170static int scd_eject(int unit);
171static int scd_stop(int unit);
172static int scd_pause(int unit);
173static int scd_resume(int unit);
174static int scd_playtracks(int unit, struct ioc_play_track *pt);
175static int scd_playmsf(int unit, struct ioc_play_msf *msf);

--- 597 unchanged lines hidden (view full) ---

773 * SCD_S_WAITFIFO: wait for param fifo to get ready, them exec. command.
774 * SCD_S_WAITREAD: wait for data ready, read data
775 * SCD_S_WAITPARAM: wait for command result params, read them, error if bad data read.
776 */
777
778static struct scd_mbx *mbxsave;
779
780static void
781scd_timeout(void *arg)
782{
783 scd_doread((int)arg, mbxsave);
784}
785
786static void
780scd_doread(int state, struct scd_mbx *mbxin)
781{
782 struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? mbxsave : mbxin;
783 int unit = mbx->unit;
784 int port = mbx->port;
785 struct buf *bp = mbx->bp;
786 struct scd_data *cd = scd_data + unit;
787 int reg,i;

--- 9 unchanged lines hidden (view full) ---

797 case SCD_S_BEGIN1:
798 /* get status */
799 mbx->count = RDELAY_WAIT;
800
801 process_attention(unit);
802 goto trystat;
803
804 case SCD_S_WAITSTAT:
787scd_doread(int state, struct scd_mbx *mbxin)
788{
789 struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? mbxsave : mbxin;
790 int unit = mbx->unit;
791 int port = mbx->port;
792 struct buf *bp = mbx->bp;
793 struct scd_data *cd = scd_data + unit;
794 int reg,i;

--- 9 unchanged lines hidden (view full) ---

804 case SCD_S_BEGIN1:
805 /* get status */
806 mbx->count = RDELAY_WAIT;
807
808 process_attention(unit);
809 goto trystat;
810
811 case SCD_S_WAITSTAT:
805 untimeout((timeout_func_t)scd_doread,(caddr_t)SCD_S_WAITSTAT);
812 untimeout(scd_timeout,(caddr_t)SCD_S_WAITSTAT);
806 if (mbx->count-- <= 0) {
807 printf("scd%d: timeout. drive busy.\n",unit);
808 goto harderr;
809 }
810
811trystat:
812 if (IS_BUSY(port)) {
813 if (mbx->count-- <= 0) {
814 printf("scd%d: timeout. drive busy.\n",unit);
815 goto harderr;
816 }
817
818trystat:
819 if (IS_BUSY(port)) {
813 timeout((timeout_func_t)scd_doread,
820 timeout(scd_timeout,
814 (caddr_t)SCD_S_WAITSTAT,hz/100); /* XXX */
815 return;
816 }
817
818 process_attention(unit);
819
820 /* reject, if audio active */
821 if (cd->audio_status & CD_AS_PLAY_IN_PROGRESS) {

--- 22 unchanged lines hidden (view full) ---

844 write_control(port, CBIT_RESULT_READY_CLEAR);
845 write_control(port, CBIT_RPARAM_CLEAR);
846 write_control(port, CBIT_DATA_READY_CLEAR);
847
848 if (FSTATUS_BIT(port, FBIT_WPARAM_READY))
849 goto writeparam;
850
851 mbx->count = 100;
821 (caddr_t)SCD_S_WAITSTAT,hz/100); /* XXX */
822 return;
823 }
824
825 process_attention(unit);
826
827 /* reject, if audio active */
828 if (cd->audio_status & CD_AS_PLAY_IN_PROGRESS) {

--- 22 unchanged lines hidden (view full) ---

851 write_control(port, CBIT_RESULT_READY_CLEAR);
852 write_control(port, CBIT_RPARAM_CLEAR);
853 write_control(port, CBIT_DATA_READY_CLEAR);
854
855 if (FSTATUS_BIT(port, FBIT_WPARAM_READY))
856 goto writeparam;
857
858 mbx->count = 100;
852 timeout((timeout_func_t)scd_doread,
859 timeout(scd_timeout,
853 (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
854 return;
855
856 case SCD_S_WAITSPIN:
860 (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
861 return;
862
863 case SCD_S_WAITSPIN:
857 untimeout((timeout_func_t)scd_doread,(caddr_t)SCD_S_WAITSPIN);
864 untimeout(scd_timeout,(caddr_t)SCD_S_WAITSPIN);
858 if (mbx->count-- <= 0) {
859 printf("scd%d: timeout waiting for drive to spin up.\n", unit);
860 goto harderr;
861 }
862 if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
865 if (mbx->count-- <= 0) {
866 printf("scd%d: timeout waiting for drive to spin up.\n", unit);
867 goto harderr;
868 }
869 if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
863 timeout((timeout_func_t)scd_doread,
870 timeout(scd_timeout,
864 (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
865 return;
866 }
867 write_control(port, CBIT_RESULT_READY_CLEAR);
868 switch ((i = inb(port+IREG_RESULT)) & 0xf0) {
869 case 0x20:
870 i = inb(port+IREG_RESULT);
871 print_error(unit, i);

--- 4 unchanged lines hidden (view full) ---

876 break;
877 }
878 XDEBUG(1, ("scd%d: DEBUG: spin up complete\n", unit));
879
880 state = SCD_S_BEGIN1;
881 goto loop;
882
883 case SCD_S_WAITFIFO:
871 (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
872 return;
873 }
874 write_control(port, CBIT_RESULT_READY_CLEAR);
875 switch ((i = inb(port+IREG_RESULT)) & 0xf0) {
876 case 0x20:
877 i = inb(port+IREG_RESULT);
878 print_error(unit, i);

--- 4 unchanged lines hidden (view full) ---

883 break;
884 }
885 XDEBUG(1, ("scd%d: DEBUG: spin up complete\n", unit));
886
887 state = SCD_S_BEGIN1;
888 goto loop;
889
890 case SCD_S_WAITFIFO:
884 untimeout((timeout_func_t)scd_doread,(caddr_t)SCD_S_WAITFIFO);
891 untimeout(scd_timeout,(caddr_t)SCD_S_WAITFIFO);
885 if (mbx->count-- <= 0) {
886 printf("scd%d: timeout. write param not ready.\n",unit);
887 goto harderr;
888 }
889 if (!FSTATUS_BIT(port, FBIT_WPARAM_READY)) {
892 if (mbx->count-- <= 0) {
893 printf("scd%d: timeout. write param not ready.\n",unit);
894 goto harderr;
895 }
896 if (!FSTATUS_BIT(port, FBIT_WPARAM_READY)) {
890 timeout((timeout_func_t)scd_doread,
897 timeout(scd_timeout,
891 (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
892 return;
893 }
894 XDEBUG(1, ("scd%d: mbx->count (writeparamwait) = %d(%d)\n", unit, mbx->count, 100));
895
896writeparam:
897 /* The reason this test isn't done 'till now is to make sure */
898 /* that it is ok to send the SPIN_UP cmd below. */
899 if (!(cd->flags & SCDSPINNING)) {
900 XDEBUG(1, ("scd%d: spinning up drive ...\n", unit));
901 outb(port+OREG_COMMAND, CMD_SPIN_UP);
902 mbx->count = 300;
898 (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
899 return;
900 }
901 XDEBUG(1, ("scd%d: mbx->count (writeparamwait) = %d(%d)\n", unit, mbx->count, 100));
902
903writeparam:
904 /* The reason this test isn't done 'till now is to make sure */
905 /* that it is ok to send the SPIN_UP cmd below. */
906 if (!(cd->flags & SCDSPINNING)) {
907 XDEBUG(1, ("scd%d: spinning up drive ...\n", unit));
908 outb(port+OREG_COMMAND, CMD_SPIN_UP);
909 mbx->count = 300;
903 timeout((timeout_func_t)scd_doread,
910 timeout(scd_timeout,
904 (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
905 return;
906 }
907
908 reg = port + OREG_WPARAMS;
909 /* send the read command */
910 disable_intr();
911 outb(reg, sdata[0]);

--- 7 unchanged lines hidden (view full) ---

919
920 mbx->count = RDELAY_WAITREAD;
921 for (i = 0; i < 50; i++) {
922 if (STATUS_BIT(port, SBIT_DATA_READY))
923 goto got_data;
924 DELAY(100);
925 }
926
911 (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
912 return;
913 }
914
915 reg = port + OREG_WPARAMS;
916 /* send the read command */
917 disable_intr();
918 outb(reg, sdata[0]);

--- 7 unchanged lines hidden (view full) ---

926
927 mbx->count = RDELAY_WAITREAD;
928 for (i = 0; i < 50; i++) {
929 if (STATUS_BIT(port, SBIT_DATA_READY))
930 goto got_data;
931 DELAY(100);
932 }
933
927 timeout((timeout_func_t)scd_doread,
934 timeout(scd_timeout,
928 (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
929 return;
930
931 case SCD_S_WAITREAD:
935 (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
936 return;
937
938 case SCD_S_WAITREAD:
932 untimeout((timeout_func_t)scd_doread,(caddr_t)SCD_S_WAITREAD);
939 untimeout(scd_timeout,(caddr_t)SCD_S_WAITREAD);
933 if (mbx->count-- <= 0) {
934 if (STATUS_BIT(port, SBIT_RESULT_READY))
935 goto got_param;
936 printf("scd%d: timeout while reading data\n",unit);
937 goto readerr;
938 }
939 if (!STATUS_BIT(port, SBIT_DATA_READY)) {
940 process_attention(unit);
941 if (!(cd->flags & SCDVALID))
942 goto changed;
940 if (mbx->count-- <= 0) {
941 if (STATUS_BIT(port, SBIT_RESULT_READY))
942 goto got_param;
943 printf("scd%d: timeout while reading data\n",unit);
944 goto readerr;
945 }
946 if (!STATUS_BIT(port, SBIT_DATA_READY)) {
947 process_attention(unit);
948 if (!(cd->flags & SCDVALID))
949 goto changed;
943 timeout((timeout_func_t)scd_doread,
950 timeout(scd_timeout,
944 (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
945 return;
946 }
947 XDEBUG(2, ("scd%d: mbx->count (after RDY_BIT) = %d(%d)\n", unit, mbx->count, RDELAY_WAITREAD));
948
949got_data:
950 /* data is ready */
951 addr = bp->b_un.b_addr + mbx->skip;

--- 4 unchanged lines hidden (view full) ---

956 for (i = 0; i < 20; i++) {
957 if (STATUS_BIT(port, SBIT_RESULT_READY))
958 goto waitfor_param;
959 DELAY(100);
960 }
961 goto waitfor_param;
962
963 case SCD_S_WAITPARAM:
951 (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
952 return;
953 }
954 XDEBUG(2, ("scd%d: mbx->count (after RDY_BIT) = %d(%d)\n", unit, mbx->count, RDELAY_WAITREAD));
955
956got_data:
957 /* data is ready */
958 addr = bp->b_un.b_addr + mbx->skip;

--- 4 unchanged lines hidden (view full) ---

963 for (i = 0; i < 20; i++) {
964 if (STATUS_BIT(port, SBIT_RESULT_READY))
965 goto waitfor_param;
966 DELAY(100);
967 }
968 goto waitfor_param;
969
970 case SCD_S_WAITPARAM:
964 untimeout((timeout_func_t)scd_doread,(caddr_t)SCD_S_WAITPARAM);
971 untimeout(scd_timeout,(caddr_t)SCD_S_WAITPARAM);
965 if (mbx->count-- <= 0) {
966 printf("scd%d: timeout waiting for params\n",unit);
967 goto readerr;
968 }
969
970waitfor_param:
971 if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
972 if (mbx->count-- <= 0) {
973 printf("scd%d: timeout waiting for params\n",unit);
974 goto readerr;
975 }
976
977waitfor_param:
978 if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
972 timeout((timeout_func_t)scd_doread,
979 timeout(scd_timeout,
973 (caddr_t)SCD_S_WAITPARAM,hz/100); /* XXX */
974 return;
975 }
976#if SCD_DEBUG
977 if (mbx->count < 100 && scd_debuglevel > 0)
978 printf("scd%d: mbx->count (paramwait) = %d(%d)\n", unit, mbx->count, 100);
979#endif
980

--- 547 unchanged lines hidden ---
980 (caddr_t)SCD_S_WAITPARAM,hz/100); /* XXX */
981 return;
982 }
983#if SCD_DEBUG
984 if (mbx->count < 100 && scd_debuglevel > 0)
985 printf("scd%d: mbx->count (paramwait) = %d(%d)\n", unit, mbx->count, 100);
986#endif
987

--- 547 unchanged lines hidden ---