Print this page
8634 epoll fails to wake on certain edge-triggered conditions
8635 epoll should not emit POLLNVAL
8636 recursive epoll should emit EPOLLRDNORM
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Igor Kozhukhov <igor@dilos.org>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 
  27 /*
  28  * dcam.c
  29  *
  30  * dcam1394 driver. Controls IIDC compliant devices attached through a
  31  * IEEE-1394 bus.
  32  */
  33 
  34 #include <sys/conf.h>
  35 #include <sys/ddi.h>
  36 #include <sys/modctl.h>
  37 #include <sys/sunndi.h>
  38 #include <sys/types.h>
  39 #include <sys/ddi.h>
  40 #include <sys/sunddi.h>
  41 #include <sys/file.h>
  42 #include <sys/errno.h>
  43 #include <sys/open.h>


1023         case DCAM1394_CMD_FRAME_SEQ_NUM_COUNT_RESET:
1024                 mutex_enter(&softc_p->dcam_frame_is_done_mutex);
1025                 softc_p->seq_count = 0;
1026                 mutex_exit(&softc_p->dcam_frame_is_done_mutex);
1027                 break;
1028 
1029         default:
1030                 rc = EIO;
1031                 break;
1032 
1033         }
1034 
1035 done:
1036         if (param_list)
1037                 kmem_free(param_list, sizeof (dcam1394_param_list_t));
1038 
1039         return (rc);
1040 }
1041 
1042 
1043 /*
1044  * dcam_chpoll
1045  */
1046 /* ARGSUSED */
1047 int
1048 dcam_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
1049     struct pollhead **phpp)
1050 {
1051         dcam_state_t    *softc_p;
1052         int              instance, ring_buff_has_data, read_ptr_id;
1053         size_t           read_ptr_pos, write_ptr_pos;
1054         short            revent;
1055 
1056         instance = DEV_TO_INSTANCE(dev);






1057 

1058         softc_p = (dcam_state_t *)ddi_get_soft_state(dcam_state_p, instance);
1059         if (softc_p == NULL) {
1060                 return (ENXIO);
1061         }
1062 
1063         read_ptr_id     = 0;
1064         revent          = 0;
1065 
1066         if (softc_p->ring_buff_p == NULL) {
1067                 ring_buff_has_data = 0;
1068         } else {
1069                 mutex_enter(&softc_p->dcam_frame_is_done_mutex);
1070 
1071                 read_ptr_pos =
1072                     ring_buff_read_ptr_pos_get(softc_p->ring_buff_p,
1073                     read_ptr_id);
1074 
1075                 write_ptr_pos =
1076                     ring_buff_write_ptr_pos_get(softc_p->ring_buff_p);
1077 
1078                 if (read_ptr_pos != write_ptr_pos) {
1079                         ring_buff_has_data = 1;
1080                 } else {
1081                         ring_buff_has_data = 0;
1082                 }
1083 
1084                 mutex_exit(&softc_p->dcam_frame_is_done_mutex);
1085         }
1086 
1087         /*
1088          * now check for events
1089          */
1090         if ((events & POLLRDNORM) && ring_buff_has_data) {
1091                 revent |= POLLRDNORM;
1092         }

1093 
1094         if ((events & POLLPRI) && softc_p->param_status) {
1095                 revent |= POLLPRI;
1096         }
1097 
1098         /* if no events have occurred */
1099         if (revent == 0) {
1100                 if (!anyyet) {
1101                         *phpp = &softc_p->dcam_pollhead;
1102                 }
1103         }
1104 
1105         *reventsp = revent;
1106 
1107         return (0);
1108 }
1109 
1110 
1111 /*
1112  * dcam_bus_reset_notify
1113  */
1114 /* ARGSUSED */
1115 void
1116 dcam_bus_reset_notify(dev_info_t *dip, ddi_eventcookie_t ev_cookie, void *arg,
1117     void *impl_data)
1118 {
1119 
1120         dcam_state_t            *softc_p;
1121         t1394_localinfo_t       *localinfo = impl_data;
1122         t1394_targetinfo_t      targetinfo;
1123 
1124         softc_p = arg;




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2017 Joyent, Inc.
  25  */
  26 
  27 
  28 /*
  29  * dcam.c
  30  *
  31  * dcam1394 driver. Controls IIDC compliant devices attached through a
  32  * IEEE-1394 bus.
  33  */
  34 
  35 #include <sys/conf.h>
  36 #include <sys/ddi.h>
  37 #include <sys/modctl.h>
  38 #include <sys/sunndi.h>
  39 #include <sys/types.h>
  40 #include <sys/ddi.h>
  41 #include <sys/sunddi.h>
  42 #include <sys/file.h>
  43 #include <sys/errno.h>
  44 #include <sys/open.h>


1024         case DCAM1394_CMD_FRAME_SEQ_NUM_COUNT_RESET:
1025                 mutex_enter(&softc_p->dcam_frame_is_done_mutex);
1026                 softc_p->seq_count = 0;
1027                 mutex_exit(&softc_p->dcam_frame_is_done_mutex);
1028                 break;
1029 
1030         default:
1031                 rc = EIO;
1032                 break;
1033 
1034         }
1035 
1036 done:
1037         if (param_list)
1038                 kmem_free(param_list, sizeof (dcam1394_param_list_t));
1039 
1040         return (rc);
1041 }
1042 
1043 



1044 /* ARGSUSED */
1045 int
1046 dcam_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
1047     struct pollhead **phpp)
1048 {
1049         dcam_state_t    *softc_p;
1050         int             instance;
1051         short           revent = 0;

1052 
1053         /*
1054          * Without the logic to perform wakeups (see comment below), reject
1055          * attempts at edge-triggered polling.
1056          */
1057         if (events & POLLET) {
1058                 return (EPERM);
1059         }
1060 
1061         instance = DEV_TO_INSTANCE(dev);
1062         softc_p = (dcam_state_t *)ddi_get_soft_state(dcam_state_p, instance);
1063         if (softc_p == NULL) {
1064                 return (ENXIO);
1065         }
1066 
1067         if (softc_p->ring_buff_p != NULL) {
1068                 size_t read_ptr_pos, write_ptr_pos;
1069 



1070                 mutex_enter(&softc_p->dcam_frame_is_done_mutex);

1071                 read_ptr_pos =
1072                     ring_buff_read_ptr_pos_get(softc_p->ring_buff_p, 0);


1073                 write_ptr_pos =
1074                     ring_buff_write_ptr_pos_get(softc_p->ring_buff_p);







1075                 mutex_exit(&softc_p->dcam_frame_is_done_mutex);

1076 
1077                 if ((events & POLLRDNORM) && read_ptr_pos != write_ptr_pos) {



1078                         revent |= POLLRDNORM;
1079                 }
1080         }
1081 
1082         if ((events & POLLPRI) && softc_p->param_status) {
1083                 revent |= POLLPRI;
1084         }
1085 
1086         /*
1087          * No portion of this driver was ever wired up to perform a
1088          * pollwakeup() on an associated pollhead.  The lack of an emitted
1089          * pollhead informs poll/devpoll that the event status of this resource
1090          * is not cacheable.
1091          */

1092         *reventsp = revent;
1093 
1094         return (0);
1095 }
1096 
1097 
1098 /*
1099  * dcam_bus_reset_notify
1100  */
1101 /* ARGSUSED */
1102 void
1103 dcam_bus_reset_notify(dev_info_t *dip, ddi_eventcookie_t ev_cookie, void *arg,
1104     void *impl_data)
1105 {
1106 
1107         dcam_state_t            *softc_p;
1108         t1394_localinfo_t       *localinfo = impl_data;
1109         t1394_targetinfo_t      targetinfo;
1110 
1111         softc_p = arg;