ia64/xen-unstable

annotate xen/common/event_channel.c @ 1920:42f37b71f9b1

bitkeeper revision 1.1108.1.29 (41056396oI8TDCaTvBdU_3II1cHF9Q)

Rename memory allocator interfaces in Xen to avoid conflicts with
Linux namespace.
author kaf24@scramble.cl.cam.ac.uk
date Mon Jul 26 20:03:34 2004 +0000 (2004-07-26)
parents 909193d7ebaa
children 613602e2d771 1e13ae874e9c f9ae44cc1373
rev   line source
kaf24@954 1 /******************************************************************************
kaf24@954 2 * event_channel.c
kaf24@954 3 *
kaf24@1509 4 * Event notifications from VIRQs, PIRQs, and other domains.
kaf24@954 5 *
kaf24@1127 6 * Copyright (c) 2003-2004, K A Fraser.
kaf24@954 7 *
kaf24@954 8 * This program is distributed in the hope that it will be useful,
kaf24@954 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
kaf24@954 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kaf24@954 11 * GNU General Public License for more details.
kaf24@954 12 *
kaf24@954 13 * You should have received a copy of the GNU General Public License
kaf24@954 14 * along with this program; if not, write to the Free Software
kaf24@954 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
kaf24@954 16 */
kaf24@954 17
kaf24@1210 18 #include <xen/config.h>
kaf24@1210 19 #include <xen/init.h>
kaf24@1210 20 #include <xen/lib.h>
kaf24@1210 21 #include <xen/errno.h>
kaf24@1210 22 #include <xen/sched.h>
kaf24@1210 23 #include <xen/event.h>
kaf24@1239 24 #include <xen/irq.h>
kaf24@954 25
kaf24@1127 26 #include <hypervisor-ifs/hypervisor-if.h>
kaf24@1127 27 #include <hypervisor-ifs/event_channel.h>
kaf24@1127 28
kaf24@1218 29 #define INIT_EVENT_CHANNELS 16
kaf24@1218 30 #define MAX_EVENT_CHANNELS 1024
kaf24@954 31
kaf24@1506 32 static int get_free_port(struct domain *d)
kaf24@954 33 {
kaf24@1127 34 int max, port;
kaf24@1127 35 event_channel_t *chn;
kaf24@1127 36
kaf24@1506 37 max = d->max_event_channel;
kaf24@1506 38 chn = d->event_channel;
kaf24@1127 39
kaf24@1127 40 for ( port = 0; port < max; port++ )
kaf24@1127 41 if ( chn[port].state == ECS_FREE )
kaf24@1127 42 break;
kaf24@1127 43
kaf24@1127 44 if ( port == max )
kaf24@1127 45 {
kaf24@1127 46 if ( max == MAX_EVENT_CHANNELS )
kaf24@1127 47 return -ENOSPC;
kaf24@1127 48
kaf24@1258 49 max *= 2;
kaf24@1127 50
kaf24@1920 51 chn = xmalloc(max * sizeof(event_channel_t));
kaf24@1127 52 if ( unlikely(chn == NULL) )
kaf24@1127 53 return -ENOMEM;
kaf24@1127 54
kaf24@1127 55 memset(chn, 0, max * sizeof(event_channel_t));
kaf24@1127 56
kaf24@1506 57 if ( d->event_channel != NULL )
kaf24@1127 58 {
kaf24@1506 59 memcpy(chn, d->event_channel, (max/2) * sizeof(event_channel_t));
kaf24@1920 60 xfree(d->event_channel);
kaf24@1127 61 }
kaf24@1127 62
kaf24@1506 63 d->event_channel = chn;
kaf24@1506 64 d->max_event_channel = max;
kaf24@1127 65 }
kaf24@1127 66
kaf24@1127 67 return port;
kaf24@1127 68 }
kaf24@1127 69
kaf24@1218 70 static long evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind)
kaf24@1127 71 {
kaf24@1506 72 struct domain *d1, *d2;
kaf24@1506 73 int port1 = 0, port2 = 0;
kaf24@1506 74 domid_t dom1 = bind->dom1, dom2 = bind->dom2;
kaf24@1506 75 long rc = 0;
kaf24@954 76
kaf24@1127 77 if ( !IS_PRIV(current) )
kaf24@1127 78 return -EPERM;
kaf24@954 79
kaf24@1129 80 if ( dom1 == DOMID_SELF )
kaf24@1129 81 dom1 = current->domain;
kaf24@1129 82 if ( dom2 == DOMID_SELF )
kaf24@1135 83 dom2 = current->domain;
kaf24@1127 84
kaf24@1506 85 if ( ((d1 = find_domain_by_id(dom1)) == NULL) ||
kaf24@1506 86 ((d2 = find_domain_by_id(dom2)) == NULL) )
kaf24@1127 87 {
kaf24@1506 88 if ( d1 != NULL )
kaf24@1506 89 put_domain(d1);
kaf24@1127 90 return -ESRCH;
kaf24@1127 91 }
kaf24@1127 92
kaf24@1127 93 /* Avoid deadlock by first acquiring lock of domain with smaller id. */
kaf24@1542 94 if ( d1 < d2 )
kaf24@954 95 {
kaf24@1506 96 spin_lock(&d1->event_channel_lock);
kaf24@1506 97 spin_lock(&d2->event_channel_lock);
kaf24@954 98 }
kaf24@954 99 else
kaf24@954 100 {
kaf24@1506 101 if ( d1 != d2 )
kaf24@1506 102 spin_lock(&d2->event_channel_lock);
kaf24@1506 103 spin_lock(&d1->event_channel_lock);
kaf24@954 104 }
kaf24@954 105
kaf24@1506 106 if ( (port1 = get_free_port(d1)) < 0 )
kaf24@954 107 {
kaf24@1129 108 rc = port1;
kaf24@1127 109 goto out;
kaf24@954 110 }
kaf24@954 111
kaf24@1329 112 /* 'Allocate' port1 before searching for a free port2. */
kaf24@1506 113 d1->event_channel[port1].state = ECS_INTERDOMAIN;
kaf24@1329 114
kaf24@1506 115 if ( (port2 = get_free_port(d2)) < 0 )
kaf24@954 116 {
kaf24@1506 117 d1->event_channel[port1].state = ECS_FREE;
kaf24@1129 118 rc = port2;
kaf24@1127 119 goto out;
kaf24@1127 120 }
kaf24@954 121
kaf24@1506 122 d1->event_channel[port1].u.remote.dom = d2;
kaf24@1506 123 d1->event_channel[port1].u.remote.port = (u16)port2;
kaf24@954 124
kaf24@1506 125 d2->event_channel[port2].u.remote.dom = d1;
kaf24@1506 126 d2->event_channel[port2].u.remote.port = (u16)port1;
kaf24@1506 127 d2->event_channel[port2].state = ECS_INTERDOMAIN;
kaf24@1127 128
kaf24@954 129 out:
kaf24@1506 130 spin_unlock(&d1->event_channel_lock);
kaf24@1506 131 if ( d1 != d2 )
kaf24@1506 132 spin_unlock(&d2->event_channel_lock);
kaf24@1127 133
kaf24@1506 134 put_domain(d1);
kaf24@1506 135 put_domain(d2);
kaf24@1127 136
kaf24@1218 137 bind->port1 = port1;
kaf24@1218 138 bind->port2 = port2;
kaf24@954 139
kaf24@954 140 return rc;
kaf24@954 141 }
kaf24@954 142
kaf24@954 143
kaf24@1218 144 static long evtchn_bind_virq(evtchn_bind_virq_t *bind)
kaf24@1218 145 {
kaf24@1506 146 struct domain *d = current;
kaf24@1506 147 int port, virq = bind->virq;
kaf24@1218 148
kaf24@1506 149 if ( virq >= ARRAY_SIZE(d->virq_to_evtchn) )
kaf24@1218 150 return -EINVAL;
kaf24@1218 151
kaf24@1506 152 spin_lock(&d->event_channel_lock);
kaf24@1218 153
kaf24@1218 154 /*
kaf24@1218 155 * Port 0 is the fallback port for VIRQs that haven't been explicitly
kaf24@1249 156 * bound yet. The exception is the 'misdirect VIRQ', which is permanently
kaf24@1218 157 * bound to port 0.
kaf24@1218 158 */
kaf24@1506 159 if ( ((port = d->virq_to_evtchn[virq]) != 0) ||
kaf24@1249 160 (virq == VIRQ_MISDIRECT) ||
kaf24@1506 161 ((port = get_free_port(d)) < 0) )
kaf24@1218 162 goto out;
kaf24@1218 163
kaf24@1506 164 d->event_channel[port].state = ECS_VIRQ;
kaf24@1506 165 d->event_channel[port].u.virq = virq;
kaf24@1218 166
kaf24@1506 167 d->virq_to_evtchn[virq] = port;
kaf24@1218 168
kaf24@1218 169 out:
kaf24@1506 170 spin_unlock(&d->event_channel_lock);
kaf24@1218 171
kaf24@1218 172 if ( port < 0 )
kaf24@1218 173 return port;
kaf24@1218 174
kaf24@1218 175 bind->port = port;
kaf24@1218 176 return 0;
kaf24@1218 177 }
kaf24@1218 178
kaf24@1218 179
kaf24@1235 180 static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)
kaf24@1235 181 {
kaf24@1506 182 struct domain *d = current;
kaf24@1506 183 int port, rc, pirq = bind->pirq;
kaf24@1235 184
kaf24@1506 185 if ( pirq >= ARRAY_SIZE(d->pirq_to_evtchn) )
kaf24@1235 186 return -EINVAL;
kaf24@1235 187
kaf24@1506 188 spin_lock(&d->event_channel_lock);
kaf24@1235 189
kaf24@1506 190 if ( ((rc = port = d->pirq_to_evtchn[pirq]) != 0) ||
kaf24@1506 191 ((rc = port = get_free_port(d)) < 0) )
kaf24@1235 192 goto out;
kaf24@1235 193
kaf24@1506 194 d->pirq_to_evtchn[pirq] = port;
kaf24@1506 195 rc = pirq_guest_bind(d, pirq,
kaf24@1253 196 !!(bind->flags & BIND_PIRQ__WILL_SHARE));
kaf24@1253 197 if ( rc != 0 )
kaf24@1239 198 {
kaf24@1506 199 d->pirq_to_evtchn[pirq] = 0;
kaf24@1251 200 DPRINTK("Couldn't bind to PIRQ %d (error=%d)\n", pirq, rc);
kaf24@1239 201 goto out;
kaf24@1239 202 }
kaf24@1239 203
kaf24@1506 204 d->event_channel[port].state = ECS_PIRQ;
kaf24@1506 205 d->event_channel[port].u.pirq = pirq;
kaf24@1235 206
kaf24@1235 207 out:
kaf24@1506 208 spin_unlock(&d->event_channel_lock);
kaf24@1235 209
kaf24@1239 210 if ( rc < 0 )
kaf24@1239 211 return rc;
kaf24@1235 212
kaf24@1235 213 bind->port = port;
kaf24@1235 214 return 0;
kaf24@1235 215 }
kaf24@1235 216
kaf24@1235 217
kaf24@1506 218 static long __evtchn_close(struct domain *d1, int port1)
kaf24@954 219 {
kaf24@1506 220 struct domain *d2 = NULL;
kaf24@1506 221 event_channel_t *chn1, *chn2;
kaf24@1506 222 int port2;
kaf24@1506 223 long rc = 0;
kaf24@954 224
kaf24@954 225 again:
kaf24@1506 226 spin_lock(&d1->event_channel_lock);
kaf24@954 227
kaf24@1506 228 chn1 = d1->event_channel;
kaf24@954 229
kaf24@1249 230 /* NB. Port 0 is special (VIRQ_MISDIRECT). Never let it be closed. */
kaf24@1506 231 if ( (port1 <= 0) || (port1 >= d1->max_event_channel) )
kaf24@954 232 {
kaf24@954 233 rc = -EINVAL;
kaf24@954 234 goto out;
kaf24@954 235 }
kaf24@954 236
kaf24@1218 237 switch ( chn1[port1].state )
kaf24@954 238 {
kaf24@1218 239 case ECS_FREE:
kaf24@1218 240 rc = -EINVAL;
kaf24@1218 241 goto out;
kaf24@1218 242
kaf24@1218 243 case ECS_UNBOUND:
kaf24@1218 244 break;
kaf24@1218 245
kaf24@1218 246 case ECS_PIRQ:
kaf24@1506 247 if ( (rc = pirq_guest_unbind(d1, chn1[port1].u.pirq)) == 0 )
kaf24@1506 248 d1->pirq_to_evtchn[chn1[port1].u.pirq] = 0;
kaf24@1218 249 break;
kaf24@1218 250
kaf24@1218 251 case ECS_VIRQ:
kaf24@1506 252 d1->virq_to_evtchn[chn1[port1].u.virq] = 0;
kaf24@1218 253 break;
kaf24@1218 254
kaf24@1218 255 case ECS_INTERDOMAIN:
kaf24@1506 256 if ( d2 == NULL )
kaf24@954 257 {
kaf24@1506 258 d2 = chn1[port1].u.remote.dom;
kaf24@1505 259
kaf24@1506 260 /* If we unlock d1 then we could lose d2. Must get a reference. */
kaf24@1506 261 if ( unlikely(!get_domain(d2)) )
kaf24@1505 262 {
kaf24@1505 263 /*
kaf24@1506 264 * Failed to obtain a reference. No matter: d2 must be dying
kaf24@1505 265 * and so will close this event channel for us.
kaf24@1505 266 */
kaf24@1506 267 d2 = NULL;
kaf24@1505 268 goto out;
kaf24@1505 269 }
kaf24@1127 270
kaf24@1542 271 if ( d1 < d2 )
kaf24@954 272 {
kaf24@1506 273 spin_lock(&d2->event_channel_lock);
kaf24@954 274 }
kaf24@1506 275 else if ( d1 != d2 )
kaf24@954 276 {
kaf24@1506 277 spin_unlock(&d1->event_channel_lock);
kaf24@1506 278 spin_lock(&d2->event_channel_lock);
kaf24@954 279 goto again;
kaf24@954 280 }
kaf24@954 281 }
kaf24@1506 282 else if ( d2 != chn1[port1].u.remote.dom )
kaf24@954 283 {
kaf24@954 284 rc = -EINVAL;
kaf24@954 285 goto out;
kaf24@954 286 }
kaf24@1505 287
kaf24@1506 288 chn2 = d2->event_channel;
kaf24@1218 289 port2 = chn1[port1].u.remote.port;
kaf24@954 290
kaf24@1506 291 if ( port2 >= d2->max_event_channel )
kaf24@1127 292 BUG();
kaf24@1218 293 if ( chn2[port2].state != ECS_INTERDOMAIN )
kaf24@1127 294 BUG();
kaf24@1506 295 if ( chn2[port2].u.remote.dom != d1 )
kaf24@1127 296 BUG();
kaf24@954 297
kaf24@1258 298 chn2[port2].state = ECS_UNBOUND;
kaf24@1218 299 break;
kaf24@1218 300
kaf24@1218 301 default:
kaf24@1218 302 BUG();
kaf24@954 303 }
kaf24@954 304
kaf24@1258 305 chn1[port1].state = ECS_FREE;
kaf24@1133 306
kaf24@954 307 out:
kaf24@1506 308 if ( d2 != NULL )
kaf24@954 309 {
kaf24@1506 310 if ( d1 != d2 )
kaf24@1506 311 spin_unlock(&d2->event_channel_lock);
kaf24@1506 312 put_domain(d2);
kaf24@954 313 }
kaf24@954 314
kaf24@1506 315 spin_unlock(&d1->event_channel_lock);
kaf24@1145 316
kaf24@954 317 return rc;
kaf24@954 318 }
kaf24@954 319
kaf24@954 320
kaf24@1218 321 static long evtchn_close(evtchn_close_t *close)
kaf24@1127 322 {
kaf24@1506 323 struct domain *d;
kaf24@1506 324 long rc;
kaf24@1506 325 domid_t dom = close->dom;
kaf24@1127 326
kaf24@1129 327 if ( dom == DOMID_SELF )
kaf24@1129 328 dom = current->domain;
kaf24@1127 329 else if ( !IS_PRIV(current) )
kaf24@1127 330 return -EPERM;
kaf24@1127 331
kaf24@1506 332 if ( (d = find_domain_by_id(dom)) == NULL )
kaf24@1127 333 return -ESRCH;
kaf24@1127 334
kaf24@1506 335 rc = __evtchn_close(d, close->port);
kaf24@1127 336
kaf24@1506 337 put_domain(d);
kaf24@1127 338 return rc;
kaf24@1127 339 }
kaf24@1127 340
kaf24@1127 341
kaf24@1218 342 static long evtchn_send(int lport)
kaf24@954 343 {
kaf24@1506 344 struct domain *ld = current, *rd;
kaf24@1506 345 int rport;
kaf24@954 346
kaf24@1506 347 spin_lock(&ld->event_channel_lock);
kaf24@954 348
kaf24@1127 349 if ( unlikely(lport < 0) ||
kaf24@1506 350 unlikely(lport >= ld->max_event_channel) ||
kaf24@1506 351 unlikely(ld->event_channel[lport].state != ECS_INTERDOMAIN) )
kaf24@954 352 {
kaf24@1506 353 spin_unlock(&ld->event_channel_lock);
kaf24@954 354 return -EINVAL;
kaf24@954 355 }
kaf24@954 356
kaf24@1506 357 rd = ld->event_channel[lport].u.remote.dom;
kaf24@1506 358 rport = ld->event_channel[lport].u.remote.port;
kaf24@1127 359
kaf24@1506 360 evtchn_set_pending(rd, rport);
kaf24@954 361
kaf24@1506 362 spin_unlock(&ld->event_channel_lock);
kaf24@954 363
kaf24@954 364 return 0;
kaf24@954 365 }
kaf24@954 366
kaf24@954 367
kaf24@1218 368 static long evtchn_status(evtchn_status_t *status)
kaf24@954 369 {
kaf24@1506 370 struct domain *d;
kaf24@1506 371 domid_t dom = status->dom;
kaf24@1506 372 int port = status->port;
kaf24@1506 373 event_channel_t *chn;
kaf24@1506 374 long rc = 0;
kaf24@1127 375
kaf24@1129 376 if ( dom == DOMID_SELF )
kaf24@1129 377 dom = current->domain;
kaf24@1127 378 else if ( !IS_PRIV(current) )
kaf24@1127 379 return -EPERM;
kaf24@1127 380
kaf24@1506 381 if ( (d = find_domain_by_id(dom)) == NULL )
kaf24@1127 382 return -ESRCH;
kaf24@954 383
kaf24@1506 384 spin_lock(&d->event_channel_lock);
kaf24@954 385
kaf24@1506 386 chn = d->event_channel;
kaf24@954 387
kaf24@1506 388 if ( (port < 0) || (port >= d->max_event_channel) )
kaf24@954 389 {
kaf24@1266 390 rc = -EINVAL;
kaf24@1266 391 goto out;
kaf24@1127 392 }
kaf24@1127 393
kaf24@1129 394 switch ( chn[port].state )
kaf24@1127 395 {
kaf24@1127 396 case ECS_FREE:
kaf24@1127 397 status->status = EVTCHNSTAT_closed;
kaf24@1127 398 break;
kaf24@1218 399 case ECS_UNBOUND:
kaf24@1218 400 status->status = EVTCHNSTAT_unbound;
kaf24@1127 401 break;
kaf24@1218 402 case ECS_INTERDOMAIN:
kaf24@1218 403 status->status = EVTCHNSTAT_interdomain;
kaf24@1218 404 status->u.interdomain.dom = chn[port].u.remote.dom->domain;
kaf24@1218 405 status->u.interdomain.port = chn[port].u.remote.port;
kaf24@1218 406 break;
kaf24@1218 407 case ECS_PIRQ:
kaf24@1218 408 status->status = EVTCHNSTAT_pirq;
kaf24@1218 409 status->u.pirq = chn[port].u.pirq;
kaf24@1218 410 break;
kaf24@1218 411 case ECS_VIRQ:
kaf24@1218 412 status->status = EVTCHNSTAT_virq;
kaf24@1218 413 status->u.virq = chn[port].u.virq;
kaf24@1127 414 break;
kaf24@1127 415 default:
kaf24@1127 416 BUG();
kaf24@954 417 }
kaf24@954 418
kaf24@1266 419 out:
kaf24@1506 420 spin_unlock(&d->event_channel_lock);
kaf24@1506 421 put_domain(d);
kaf24@1266 422 return rc;
kaf24@954 423 }
kaf24@954 424
kaf24@954 425
kaf24@1127 426 long do_event_channel_op(evtchn_op_t *uop)
kaf24@954 427 {
kaf24@954 428 long rc;
kaf24@1127 429 evtchn_op_t op;
kaf24@954 430
kaf24@1127 431 if ( copy_from_user(&op, uop, sizeof(op)) != 0 )
kaf24@1127 432 return -EFAULT;
kaf24@1127 433
kaf24@1127 434 switch ( op.cmd )
kaf24@954 435 {
kaf24@1218 436 case EVTCHNOP_bind_interdomain:
kaf24@1218 437 rc = evtchn_bind_interdomain(&op.u.bind_interdomain);
kaf24@1235 438 if ( (rc == 0) && (copy_to_user(uop, &op, sizeof(op)) != 0) )
kaf24@1218 439 rc = -EFAULT; /* Cleaning up here would be a mess! */
kaf24@1218 440 break;
kaf24@1218 441
kaf24@1218 442 case EVTCHNOP_bind_virq:
kaf24@1218 443 rc = evtchn_bind_virq(&op.u.bind_virq);
kaf24@1235 444 if ( (rc == 0) && (copy_to_user(uop, &op, sizeof(op)) != 0) )
kaf24@1235 445 rc = -EFAULT; /* Cleaning up here would be a mess! */
kaf24@1235 446 break;
kaf24@1235 447
kaf24@1235 448 case EVTCHNOP_bind_pirq:
kaf24@1235 449 rc = evtchn_bind_pirq(&op.u.bind_pirq);
kaf24@1235 450 if ( (rc == 0) && (copy_to_user(uop, &op, sizeof(op)) != 0) )
kaf24@1127 451 rc = -EFAULT; /* Cleaning up here would be a mess! */
kaf24@954 452 break;
kaf24@954 453
kaf24@954 454 case EVTCHNOP_close:
kaf24@1218 455 rc = evtchn_close(&op.u.close);
kaf24@954 456 break;
kaf24@954 457
kaf24@954 458 case EVTCHNOP_send:
kaf24@1218 459 rc = evtchn_send(op.u.send.local_port);
kaf24@954 460 break;
kaf24@954 461
kaf24@954 462 case EVTCHNOP_status:
kaf24@1218 463 rc = evtchn_status(&op.u.status);
kaf24@1235 464 if ( (rc == 0) && (copy_to_user(uop, &op, sizeof(op)) != 0) )
kaf24@1127 465 rc = -EFAULT;
kaf24@954 466 break;
kaf24@954 467
kaf24@954 468 default:
kaf24@954 469 rc = -ENOSYS;
kaf24@954 470 break;
kaf24@954 471 }
kaf24@954 472
kaf24@954 473 return rc;
kaf24@954 474 }
kaf24@954 475
kaf24@954 476
kaf24@1506 477 int init_event_channels(struct domain *d)
kaf24@1218 478 {
kaf24@1506 479 spin_lock_init(&d->event_channel_lock);
kaf24@1920 480 d->event_channel = xmalloc(INIT_EVENT_CHANNELS * sizeof(event_channel_t));
kaf24@1506 481 if ( unlikely(d->event_channel == NULL) )
kaf24@1218 482 return -ENOMEM;
kaf24@1506 483 d->max_event_channel = INIT_EVENT_CHANNELS;
kaf24@1506 484 memset(d->event_channel, 0, INIT_EVENT_CHANNELS * sizeof(event_channel_t));
kaf24@1506 485 d->event_channel[0].state = ECS_VIRQ;
kaf24@1506 486 d->event_channel[0].u.virq = VIRQ_MISDIRECT;
kaf24@1218 487 return 0;
kaf24@1218 488 }
kaf24@1218 489
kaf24@1218 490
kaf24@1506 491 void destroy_event_channels(struct domain *d)
kaf24@954 492 {
kaf24@954 493 int i;
kaf24@1506 494 if ( d->event_channel != NULL )
kaf24@954 495 {
kaf24@1506 496 for ( i = 0; i < d->max_event_channel; i++ )
kaf24@1506 497 (void)__evtchn_close(d, i);
kaf24@1920 498 xfree(d->event_channel);
kaf24@954 499 }
kaf24@954 500 }