VirtualBox

Changeset 44809 in vbox for trunk/src/VBox/Devices/Serial


Ignore:
Timestamp:
Feb 24, 2013 7:31:54 PM (12 years ago)
Author:
vboxsync
Message:

DevSerial.cpp: Cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DevSerial.cpp

    r44528 r44809  
    66
    77/*
    8  * Copyright (C) 2006-2012 Oracle Corporation
     8 * Copyright (C) 2006-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    160160 * @implements  PDMICHARPORT
    161161 */
    162 struct SerialState
     162typedef struct SerialState
    163163{
    164164    /** Access critical section. */
     
    227227
    228228#ifdef VBOX_SERIAL_PCI
    229     PCIDEVICE                       dev;
     229    PCIDEVICE                       PciDev;
    230230#endif /* VBOX_SERIAL_PCI */
    231 };
     231} DEVSERIAL;
     232/** Pointer to the serial device state. */
     233typedef DEVSERIAL *PDEVSERIAL;
    232234
    233235#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    234236
    235 
    236 #ifdef VBOX_SERIAL_PCI
    237 #define PCIDEV_2_SERIALSTATE(pPciDev)           ( (SerialState *)((uintptr_t)(pPciDev) - RT_OFFSETOF(SerialState, dev)) )
    238 #endif /* VBOX_SERIAL_PCI */
    239 #define PDMIBASE_2_SERIALSTATE(pInstance)       ( (SerialState *)((uintptr_t)(pInterface) - RT_OFFSETOF(SerialState, IBase)) )
    240 #define PDMICHARPORT_2_SERIALSTATE(pInstance)   ( (SerialState *)((uintptr_t)(pInterface) - RT_OFFSETOF(SerialState, ICharPort)) )
    241 
    242 
    243 /*******************************************************************************
    244 *   Internal Functions                                                         *
    245 *******************************************************************************/
    246 RT_C_DECLS_BEGIN
    247 PDMBOTHCBDECL(int) serialIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
    248 PDMBOTHCBDECL(int) serialIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
    249 RT_C_DECLS_END
    250 
    251237#ifdef IN_RING3
    252238
    253 static int serial_can_receive(SerialState *s);
    254 static void serial_receive(void *opaque, const uint8_t *buf, int size);
    255 
    256 static void fifo_clear(SerialState *s, int fifo)
    257 {
    258     SerialFifo *f = (fifo) ? &s->recv_fifo : &s->xmit_fifo;
     239static int serial_can_receive(PDEVSERIAL pThis);
     240static void serial_receive(PDEVSERIAL pThis, const uint8_t *buf, int size);
     241
     242static void fifo_clear(PDEVSERIAL pThis, int fifo)
     243{
     244    SerialFifo *f = (fifo) ? &pThis->recv_fifo : &pThis->xmit_fifo;
    259245    memset(f->data, 0, UART_FIFO_LENGTH);
    260246    f->count = 0;
     
    263249}
    264250
    265 static int fifo_put(SerialState *s, int fifo, uint8_t chr)
    266 {
    267     SerialFifo *f = (fifo) ? &s->recv_fifo : &s->xmit_fifo;
     251static int fifo_put(PDEVSERIAL pThis, int fifo, uint8_t chr)
     252{
     253    SerialFifo *f = (fifo) ? &pThis->recv_fifo : &pThis->xmit_fifo;
    268254
    269255    /* Receive overruns do not overwrite FIFO contents. */
     
    280266        ++f->tail;
    281267    else if (fifo == RECV_FIFO)
    282         s->lsr |= UART_LSR_OE;
     268        pThis->lsr |= UART_LSR_OE;
    283269
    284270    return 1;
    285271}
    286272
    287 static uint8_t fifo_get(SerialState *s, int fifo)
    288 {
    289     SerialFifo *f = (fifo) ? &s->recv_fifo : &s->xmit_fifo;
     273static uint8_t fifo_get(PDEVSERIAL pThis, int fifo)
     274{
     275    SerialFifo *f = (fifo) ? &pThis->recv_fifo : &pThis->xmit_fifo;
    290276    uint8_t c;
    291277
     
    301287}
    302288
    303 static void serial_update_irq(SerialState *s)
     289static void serial_update_irq(PDEVSERIAL pThis)
    304290{
    305291    uint8_t tmp_iir = UART_IIR_NO_INT;
    306292
    307     if (   (s->ier & UART_IER_RLSI)
    308         && (s->lsr & UART_LSR_INT_ANY)) {
     293    if (   (pThis->ier & UART_IER_RLSI)
     294        && (pThis->lsr & UART_LSR_INT_ANY)) {
    309295        tmp_iir = UART_IIR_RLSI;
    310     } else if ((s->ier & UART_IER_RDI) && s->timeout_ipending) {
    311         /* Note that(s->ier & UART_IER_RDI) can mask this interrupt,
     296    } else if ((pThis->ier & UART_IER_RDI) && pThis->timeout_ipending) {
     297        /* Note that(pThis->ier & UART_IER_RDI) can mask this interrupt,
    312298         * this is not in the specification but is observed on existing
    313299         * hardware. */
    314300        tmp_iir = UART_IIR_CTI;
    315     } else if (   (s->ier & UART_IER_RDI)
    316                && (s->lsr & UART_LSR_DR)
    317                && (   !(s->fcr & UART_FCR_FE)
    318                    || s->recv_fifo.count >= s->recv_fifo.itl)) {
     301    } else if (   (pThis->ier & UART_IER_RDI)
     302               && (pThis->lsr & UART_LSR_DR)
     303               && (   !(pThis->fcr & UART_FCR_FE)
     304                   || pThis->recv_fifo.count >= pThis->recv_fifo.itl)) {
    319305        tmp_iir = UART_IIR_RDI;
    320     } else if (   (s->ier & UART_IER_THRI)
    321                && s->thr_ipending) {
     306    } else if (   (pThis->ier & UART_IER_THRI)
     307               && pThis->thr_ipending) {
    322308        tmp_iir = UART_IIR_THRI;
    323     } else if (   (s->ier & UART_IER_MSI)
    324                && (s->msr & UART_MSR_ANY_DELTA)) {
     309    } else if (   (pThis->ier & UART_IER_MSI)
     310               && (pThis->msr & UART_MSR_ANY_DELTA)) {
    325311        tmp_iir = UART_IIR_MSI;
    326312    }
    327     s->iir = tmp_iir | (s->iir & 0xF0);
     313    pThis->iir = tmp_iir | (pThis->iir & 0xF0);
    328314
    329315    /** XXX only call the SetIrq function if the state really changes! */
    330316    if (tmp_iir != UART_IIR_NO_INT) {
    331         Log(("serial_update_irq %d 1\n", s->irq));
     317        Log(("serial_update_irq %d 1\n", pThis->irq));
    332318# ifdef VBOX_SERIAL_PCI
    333         PDMDevHlpPCISetIrqNoWait(s->CTX_SUFF(pDevIns), 0, 1);
     319        PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 1);
    334320# else /* !VBOX_SERIAL_PCI */
    335         PDMDevHlpISASetIrqNoWait(s->CTX_SUFF(pDevIns), s->irq, 1);
     321        PDMDevHlpISASetIrqNoWait(pThis->CTX_SUFF(pDevIns), pThis->irq, 1);
    336322# endif /* !VBOX_SERIAL_PCI */
    337323    } else {
    338         Log(("serial_update_irq %d 0\n", s->irq));
     324        Log(("serial_update_irq %d 0\n", pThis->irq));
    339325# ifdef VBOX_SERIAL_PCI
    340         PDMDevHlpPCISetIrqNoWait(s->CTX_SUFF(pDevIns), 0, 0);
     326        PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 0);
    341327# else /* !VBOX_SERIAL_PCI */
    342         PDMDevHlpISASetIrqNoWait(s->CTX_SUFF(pDevIns), s->irq, 0);
     328        PDMDevHlpISASetIrqNoWait(pThis->CTX_SUFF(pDevIns), pThis->irq, 0);
    343329# endif /* !VBOX_SERIAL_PCI */
    344330    }
    345331}
    346332
    347 static void serial_tsr_retry_update_parameters(SerialState *s, uint64_t tf)
    348 {
    349     s->tsr_retry_bound_max = RT_MAX((tf * MAX_XMIT_RETRY_TIME) / s->char_transmit_time, MIN_XMIT_RETRY);
    350     s->tsr_retry_bound_min = RT_MAX(s->tsr_retry_bound_max / (1000 * MAX_XMIT_RETRY_TIME), MIN_XMIT_RETRY);
     333static void serial_tsr_retry_update_parameters(PDEVSERIAL pThis, uint64_t tf)
     334{
     335    pThis->tsr_retry_bound_max = RT_MAX((tf * MAX_XMIT_RETRY_TIME) / pThis->char_transmit_time, MIN_XMIT_RETRY);
     336    pThis->tsr_retry_bound_min = RT_MAX(pThis->tsr_retry_bound_max / (1000 * MAX_XMIT_RETRY_TIME), MIN_XMIT_RETRY);
    351337    /* for simplicity just reset to max retry count */
    352     s->tsr_retry_bound = s->tsr_retry_bound_max;
    353 }
    354 
    355 static void serial_tsr_retry_bound_reached(SerialState *s)
     338    pThis->tsr_retry_bound = pThis->tsr_retry_bound_max;
     339}
     340
     341static void serial_tsr_retry_bound_reached(PDEVSERIAL pThis)
    356342{
    357343    /* this is most likely means we have some backend connection issues */
    358344    /* decrement the retry bound */
    359     s->tsr_retry_bound = RT_MAX(s->tsr_retry_bound / (10 * MAX_XMIT_RETRY_TIME), s->tsr_retry_bound_min);
    360 }
    361 
    362 static void serial_tsr_retry_succeeded(SerialState *s)
     345    pThis->tsr_retry_bound = RT_MAX(pThis->tsr_retry_bound / (10 * MAX_XMIT_RETRY_TIME), pThis->tsr_retry_bound_min);
     346}
     347
     348static void serial_tsr_retry_succeeded(PDEVSERIAL pThis)
    363349{
    364350    /* success means we have a backend connection working OK,
    365351     * set retry bound to its maximum value */
    366     s->tsr_retry_bound = s->tsr_retry_bound_max;
    367 }
    368 
    369 static void serial_update_parameters(SerialState *s)
     352    pThis->tsr_retry_bound = pThis->tsr_retry_bound_max;
     353}
     354
     355static void serial_update_parameters(PDEVSERIAL pThis)
    370356{
    371357    int speed, parity, data_bits, stop_bits, frame_size;
    372358
    373     if (s->divider == 0)
     359    if (pThis->divider == 0)
    374360        return;
    375361
    376362    frame_size = 1;
    377     if (s->lcr & 0x08) {
     363    if (pThis->lcr & 0x08) {
    378364        frame_size++;
    379         if (s->lcr & 0x10)
     365        if (pThis->lcr & 0x10)
    380366            parity = 'E';
    381367        else
     
    384370            parity = 'N';
    385371    }
    386     if (s->lcr & 0x04)
     372    if (pThis->lcr & 0x04)
    387373        stop_bits = 2;
    388374    else
    389375        stop_bits = 1;
    390376
    391     data_bits = (s->lcr & 0x03) + 5;
     377    data_bits = (pThis->lcr & 0x03) + 5;
    392378    frame_size += data_bits + stop_bits;
    393     speed = 115200 / s->divider;
    394     uint64_t tf = TMTimerGetFreq(CTX_SUFF(s->transmit_timer));
    395     s->char_transmit_time = (tf / speed) * frame_size;
    396     serial_tsr_retry_update_parameters(s, tf);
     379    speed = 115200 / pThis->divider;
     380    uint64_t tf = TMTimerGetFreq(CTX_SUFF(pThis->transmit_timer));
     381    pThis->char_transmit_time = (tf / speed) * frame_size;
     382    serial_tsr_retry_update_parameters(pThis, tf);
    397383
    398384    Log(("speed=%d parity=%c data=%d stop=%d\n", speed, parity, data_bits, stop_bits));
    399385
    400     if (RT_LIKELY(s->pDrvChar))
    401         s->pDrvChar->pfnSetParameters(s->pDrvChar, speed, parity, data_bits, stop_bits);
    402 }
    403 
    404 static void serial_xmit(void *opaque, bool bRetryXmit)
    405 {
    406     SerialState *s = (SerialState*)opaque;
    407 
    408     if (s->tsr_retry <= 0) {
    409         if (s->fcr & UART_FCR_FE) {
    410             s->tsr = fifo_get(s, XMIT_FIFO);
    411             if (!s->xmit_fifo.count)
    412                 s->lsr |= UART_LSR_THRE;
     386    if (RT_LIKELY(pThis->pDrvChar))
     387        pThis->pDrvChar->pfnSetParameters(pThis->pDrvChar, speed, parity, data_bits, stop_bits);
     388}
     389
     390static void serial_xmit(PDEVSERIAL pThis, bool bRetryXmit)
     391{
     392    if (pThis->tsr_retry <= 0) {
     393        if (pThis->fcr & UART_FCR_FE) {
     394            pThis->tsr = fifo_get(pThis, XMIT_FIFO);
     395            if (!pThis->xmit_fifo.count)
     396                pThis->lsr |= UART_LSR_THRE;
    413397        } else {
    414             s->tsr = s->thr;
    415             s->lsr |= UART_LSR_THRE;
    416         }
    417     }
    418 
    419     if (s->mcr & UART_MCR_LOOP) {
     398            pThis->tsr = pThis->thr;
     399            pThis->lsr |= UART_LSR_THRE;
     400        }
     401    }
     402
     403    if (pThis->mcr & UART_MCR_LOOP) {
    420404        /* in loopback mode, say that we just received a char */
    421         serial_receive(s, &s->tsr, 1);
    422     } else if (   RT_LIKELY(s->pDrvChar)
    423                && RT_FAILURE(s->pDrvChar->pfnWrite(s->pDrvChar, &s->tsr, 1))) {
    424         if ((s->tsr_retry >= 0) && ((!bRetryXmit) || (s->tsr_retry <= s->tsr_retry_bound))) {
    425             if (!s->tsr_retry)
    426                 s->tsr_retry = 1; /* make sure the retry state is always set */
     405        serial_receive(pThis, &pThis->tsr, 1);
     406    } else if (   RT_LIKELY(pThis->pDrvChar)
     407               && RT_FAILURE(pThis->pDrvChar->pfnWrite(pThis->pDrvChar, &pThis->tsr, 1))) {
     408        if ((pThis->tsr_retry >= 0) && ((!bRetryXmit) || (pThis->tsr_retry <= pThis->tsr_retry_bound))) {
     409            if (!pThis->tsr_retry)
     410                pThis->tsr_retry = 1; /* make sure the retry state is always set */
    427411            else if (bRetryXmit) /* do not increase the retry count if the retry is actually caused by next char write */
    428                 s->tsr_retry++;
    429 
    430             TMTimerSet(CTX_SUFF(s->transmit_timer), TMTimerGet(CTX_SUFF(s->transmit_timer)) + s->char_transmit_time * 4);
     412                pThis->tsr_retry++;
     413
     414            TMTimerSet(CTX_SUFF(pThis->transmit_timer), TMTimerGet(CTX_SUFF(pThis->transmit_timer)) + pThis->char_transmit_time * 4);
    431415            return;
    432416        } else {
    433417            /* drop this character. */
    434             s->tsr_retry = 0;
    435             serial_tsr_retry_bound_reached(s);
     418            pThis->tsr_retry = 0;
     419            serial_tsr_retry_bound_reached(pThis);
    436420        }
    437421    }
    438422    else {
    439         s->tsr_retry = 0;
    440         serial_tsr_retry_succeeded(s);
    441     }
    442 
    443     if (!(s->lsr & UART_LSR_THRE))
    444         TMTimerSet(CTX_SUFF(s->transmit_timer),
    445                    TMTimerGet(CTX_SUFF(s->transmit_timer)) + s->char_transmit_time);
    446 
    447     if (s->lsr & UART_LSR_THRE) {
    448         s->lsr |= UART_LSR_TEMT;
    449         s->thr_ipending = 1;
    450         serial_update_irq(s);
     423        pThis->tsr_retry = 0;
     424        serial_tsr_retry_succeeded(pThis);
     425    }
     426
     427    if (!(pThis->lsr & UART_LSR_THRE))
     428        TMTimerSet(CTX_SUFF(pThis->transmit_timer),
     429                   TMTimerGet(CTX_SUFF(pThis->transmit_timer)) + pThis->char_transmit_time);
     430
     431    if (pThis->lsr & UART_LSR_THRE) {
     432        pThis->lsr |= UART_LSR_TEMT;
     433        pThis->thr_ipending = 1;
     434        serial_update_irq(pThis);
    451435    }
    452436}
     
    454438#endif /* IN_RING3 */
    455439
    456 static int serial_ioport_write(SerialState *s, uint32_t addr, uint32_t val)
     440static int serial_ioport_write(PDEVSERIAL pThis, uint32_t addr, uint32_t val)
    457441{
    458442    addr &= 7;
    459443
    460444#ifndef IN_RING3
    461     NOREF(s);
     445    NOREF(pThis);
    462446    return VINF_IOM_R3_IOPORT_WRITE;
    463447#else
     
    465449    default:
    466450    case 0:
    467         if (s->lcr & UART_LCR_DLAB) {
    468             s->divider = (s->divider & 0xff00) | val;
    469             serial_update_parameters(s);
     451        if (pThis->lcr & UART_LCR_DLAB) {
     452            pThis->divider = (pThis->divider & 0xff00) | val;
     453            serial_update_parameters(pThis);
    470454        } else {
    471             s->thr = (uint8_t) val;
    472             if (s->fcr & UART_FCR_FE) {
    473                 fifo_put(s, XMIT_FIFO, s->thr);
    474                 s->thr_ipending = 0;
    475                 s->lsr &= ~UART_LSR_TEMT;
    476                 s->lsr &= ~UART_LSR_THRE;
    477                 serial_update_irq(s);
     455            pThis->thr = (uint8_t) val;
     456            if (pThis->fcr & UART_FCR_FE) {
     457                fifo_put(pThis, XMIT_FIFO, pThis->thr);
     458                pThis->thr_ipending = 0;
     459                pThis->lsr &= ~UART_LSR_TEMT;
     460                pThis->lsr &= ~UART_LSR_THRE;
     461                serial_update_irq(pThis);
    478462            } else {
    479                 s->thr_ipending = 0;
    480                 s->lsr &= ~UART_LSR_THRE;
    481                 serial_update_irq(s);
     463                pThis->thr_ipending = 0;
     464                pThis->lsr &= ~UART_LSR_THRE;
     465                serial_update_irq(pThis);
    482466            }
    483             serial_xmit(s, false);
     467            serial_xmit(pThis, false);
    484468        }
    485469        break;
    486470    case 1:
    487         if (s->lcr & UART_LCR_DLAB) {
    488             s->divider = (s->divider & 0x00ff) | (val << 8);
    489             serial_update_parameters(s);
     471        if (pThis->lcr & UART_LCR_DLAB) {
     472            pThis->divider = (pThis->divider & 0x00ff) | (val << 8);
     473            serial_update_parameters(pThis);
    490474        } else {
    491             s->ier = val & 0x0f;
    492             if (s->lsr & UART_LSR_THRE) {
    493                 s->thr_ipending = 1;
    494                 serial_update_irq(s);
     475            pThis->ier = val & 0x0f;
     476            if (pThis->lsr & UART_LSR_THRE) {
     477                pThis->thr_ipending = 1;
     478                serial_update_irq(pThis);
    495479            }
    496480        }
    497481        break;
    498482    case 2:
    499         if (!s->f16550AEnabled)
     483        if (!pThis->f16550AEnabled)
    500484            break;
    501485
    502486        val = val & 0xFF;
    503487
    504         if (s->fcr == val)
     488        if (pThis->fcr == val)
    505489            break;
    506490
    507491        /* Did the enable/disable flag change? If so, make sure FIFOs get flushed */
    508         if ((val ^ s->fcr) & UART_FCR_FE)
     492        if ((val ^ pThis->fcr) & UART_FCR_FE)
    509493            val |= UART_FCR_XFR | UART_FCR_RFR;
    510494
    511495        /* FIFO clear */
    512496        if (val & UART_FCR_RFR) {
    513             TMTimerStop(s->fifo_timeout_timer);
    514             s->timeout_ipending = 0;
    515             fifo_clear(s, RECV_FIFO);
     497            TMTimerStop(pThis->fifo_timeout_timer);
     498            pThis->timeout_ipending = 0;
     499            fifo_clear(pThis, RECV_FIFO);
    516500        }
    517501        if (val & UART_FCR_XFR) {
    518             fifo_clear(s, XMIT_FIFO);
     502            fifo_clear(pThis, XMIT_FIFO);
    519503        }
    520504
    521505        if (val & UART_FCR_FE) {
    522             s->iir |= UART_IIR_FE;
     506            pThis->iir |= UART_IIR_FE;
    523507            /* Set RECV_FIFO trigger Level */
    524508            switch (val & 0xC0) {
    525509            case UART_FCR_ITL_1:
    526                 s->recv_fifo.itl = 1;
     510                pThis->recv_fifo.itl = 1;
    527511                break;
    528512            case UART_FCR_ITL_2:
    529                 s->recv_fifo.itl = 4;
     513                pThis->recv_fifo.itl = 4;
    530514                break;
    531515            case UART_FCR_ITL_3:
    532                 s->recv_fifo.itl = 8;
     516                pThis->recv_fifo.itl = 8;
    533517                break;
    534518            case UART_FCR_ITL_4:
    535                 s->recv_fifo.itl = 14;
     519                pThis->recv_fifo.itl = 14;
    536520                break;
    537521            }
    538522        } else
    539             s->iir &= ~UART_IIR_FE;
     523            pThis->iir &= ~UART_IIR_FE;
    540524
    541525        /* Set fcr - or at least the bits in it that are supposed to "stick" */
    542         s->fcr = val & 0xC9;
    543         serial_update_irq(s);
     526        pThis->fcr = val & 0xC9;
     527        serial_update_irq(pThis);
    544528        break;
    545529    case 3:
    546530        {
    547531            int break_enable;
    548             s->lcr = val;
    549             serial_update_parameters(s);
     532            pThis->lcr = val;
     533            serial_update_parameters(pThis);
    550534            break_enable = (val >> 6) & 1;
    551             if (break_enable != s->last_break_enable) {
    552                 s->last_break_enable = break_enable;
    553                 if (RT_LIKELY(s->pDrvChar))
     535            if (break_enable != pThis->last_break_enable) {
     536                pThis->last_break_enable = break_enable;
     537                if (RT_LIKELY(pThis->pDrvChar))
    554538                {
    555539                    Log(("serial_ioport_write: Set break %d\n", break_enable));
    556                     int rc = s->pDrvChar->pfnSetBreak(s->pDrvChar, !!break_enable);
     540                    int rc = pThis->pDrvChar->pfnSetBreak(pThis->pDrvChar, !!break_enable);
    557541                    AssertRC(rc);
    558542                }
     
    561545        break;
    562546    case 4:
    563         s->mcr = val & 0x1f;
    564         if (RT_LIKELY(s->pDrvChar))
     547        pThis->mcr = val & 0x1f;
     548        if (RT_LIKELY(pThis->pDrvChar))
    565549        {
    566             int rc = s->pDrvChar->pfnSetModemLines(s->pDrvChar,
    567                                                    !!(s->mcr & UART_MCR_RTS),
    568                                                    !!(s->mcr & UART_MCR_DTR));
     550            int rc = pThis->pDrvChar->pfnSetModemLines(pThis->pDrvChar,
     551                                                   !!(pThis->mcr & UART_MCR_RTS),
     552                                                   !!(pThis->mcr & UART_MCR_DTR));
    569553            AssertRC(rc);
    570554        }
     
    575559        break;
    576560    case 7:
    577         s->scr = val;
     561        pThis->scr = val;
    578562        break;
    579563    }
     
    582566}
    583567
    584 static uint32_t serial_ioport_read(void *opaque, uint32_t addr, int *pRC)
    585 {
    586     SerialState *s = (SerialState *)opaque;
     568static uint32_t serial_ioport_read(PDEVSERIAL pThis, uint32_t addr, int *pRC)
     569{
    587570    uint32_t ret = ~0U;
    588571
     
    593576    default:
    594577    case 0:
    595         if (s->lcr & UART_LCR_DLAB) {
     578        if (pThis->lcr & UART_LCR_DLAB) {
    596579            /* DLAB == 1: divisor latch (LS) */
    597             ret = s->divider & 0xff;
     580            ret = pThis->divider & 0xff;
    598581        } else {
    599582#ifndef IN_RING3
    600583            *pRC = VINF_IOM_R3_IOPORT_READ;
    601584#else
    602             if (s->fcr & UART_FCR_FE) {
    603                 ret = fifo_get(s, RECV_FIFO);
    604                 if (s->recv_fifo.count == 0)
    605                     s->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
     585            if (pThis->fcr & UART_FCR_FE) {
     586                ret = fifo_get(pThis, RECV_FIFO);
     587                if (pThis->recv_fifo.count == 0)
     588                    pThis->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
    606589                else
    607                     TMTimerSet(s->fifo_timeout_timer,
    608                                TMTimerGet(s->fifo_timeout_timer) + s->char_transmit_time * 4);
    609                 s->timeout_ipending = 0;
     590                    TMTimerSet(pThis->fifo_timeout_timer,
     591                               TMTimerGet(pThis->fifo_timeout_timer) + pThis->char_transmit_time * 4);
     592                pThis->timeout_ipending = 0;
    610593            } else {
    611                 Log(("serial_io_port_read: read 0x%X\n", s->rbr));
    612                 ret = s->rbr;
    613                 s->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
     594                Log(("serial_io_port_read: read 0x%X\n", pThis->rbr));
     595                ret = pThis->rbr;
     596                pThis->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
    614597            }
    615             serial_update_irq(s);
    616             if (s->fRecvWaiting)
     598            serial_update_irq(pThis);
     599            if (pThis->fRecvWaiting)
    617600            {
    618                 s->fRecvWaiting = false;
    619                 int rc = RTSemEventSignal(s->ReceiveSem);
     601                pThis->fRecvWaiting = false;
     602                int rc = RTSemEventSignal(pThis->ReceiveSem);
    620603                AssertRC(rc);
    621604            }
     
    624607        break;
    625608    case 1:
    626         if (s->lcr & UART_LCR_DLAB) {
     609        if (pThis->lcr & UART_LCR_DLAB) {
    627610            /* DLAB == 1: divisor latch (MS) */
    628             ret = (s->divider >> 8) & 0xff;
     611            ret = (pThis->divider >> 8) & 0xff;
    629612        } else {
    630             ret = s->ier;
     613            ret = pThis->ier;
    631614        }
    632615        break;
     
    635618        *pRC = VINF_IOM_R3_IOPORT_READ;
    636619#else
    637         ret = s->iir;
     620        ret = pThis->iir;
    638621        if ((ret & UART_IIR_ID) == UART_IIR_THRI) {
    639             s->thr_ipending = 0;
    640             serial_update_irq(s);
     622            pThis->thr_ipending = 0;
     623            serial_update_irq(pThis);
    641624        }
    642625        /* reset msr changed bit */
    643         s->msr_changed = false;
     626        pThis->msr_changed = false;
    644627#endif
    645628        break;
    646629    case 3:
    647         ret = s->lcr;
     630        ret = pThis->lcr;
    648631        break;
    649632    case 4:
    650         ret = s->mcr;
     633        ret = pThis->mcr;
    651634        break;
    652635    case 5:
    653         if ((s->lsr & UART_LSR_DR) == 0 && s->fYieldOnLSRRead)
     636        if ((pThis->lsr & UART_LSR_DR) == 0 && pThis->fYieldOnLSRRead)
    654637        {
    655638            /* No data available and yielding is enabled, so yield in ring3. */
     
    661644#endif
    662645        }
    663         ret = s->lsr;
     646        ret = pThis->lsr;
    664647        /* Clear break and overrun interrupts */
    665         if (s->lsr & (UART_LSR_BI|UART_LSR_OE)) {
     648        if (pThis->lsr & (UART_LSR_BI|UART_LSR_OE)) {
    666649#ifndef IN_RING3
    667650            *pRC = VINF_IOM_R3_IOPORT_READ;
    668651#else
    669             s->lsr &= ~(UART_LSR_BI|UART_LSR_OE);
    670             serial_update_irq(s);
     652            pThis->lsr &= ~(UART_LSR_BI|UART_LSR_OE);
     653            serial_update_irq(pThis);
    671654#endif
    672655        }
    673656        break;
    674657    case 6:
    675         if (s->mcr & UART_MCR_LOOP) {
     658        if (pThis->mcr & UART_MCR_LOOP) {
    676659            /* in loopback, the modem output pins are connected to the
    677660               inputs */
    678             ret = (s->mcr & 0x0c) << 4;
    679             ret |= (s->mcr & 0x02) << 3;
    680             ret |= (s->mcr & 0x01) << 5;
     661            ret = (pThis->mcr & 0x0c) << 4;
     662            ret |= (pThis->mcr & 0x02) << 3;
     663            ret |= (pThis->mcr & 0x01) << 5;
    681664        } else {
    682             ret = s->msr;
     665            ret = pThis->msr;
    683666            /* Clear delta bits & msr int after read, if they were set */
    684             if (s->msr & UART_MSR_ANY_DELTA) {
     667            if (pThis->msr & UART_MSR_ANY_DELTA) {
    685668#ifndef IN_RING3
    686669                *pRC = VINF_IOM_R3_IOPORT_READ;
    687670#else
    688                 s->msr &= 0xF0;
    689                 serial_update_irq(s);
     671                pThis->msr &= 0xF0;
     672                serial_update_irq(pThis);
    690673#endif
    691674            }
     
    693676        break;
    694677    case 7:
    695         ret = s->scr;
     678        ret = pThis->scr;
    696679        break;
    697680    }
     
    701684#ifdef IN_RING3
    702685
    703 static int serial_can_receive(SerialState *s)
    704 {
    705     if (s->fcr & UART_FCR_FE) {
    706         if (s->recv_fifo.count < UART_FIFO_LENGTH)
    707             return (s->recv_fifo.count <= s->recv_fifo.itl)
    708                 ? s->recv_fifo.itl - s->recv_fifo.count : 1;
     686static int serial_can_receive(PDEVSERIAL pThis)
     687{
     688    if (pThis->fcr & UART_FCR_FE) {
     689        if (pThis->recv_fifo.count < UART_FIFO_LENGTH)
     690            return (pThis->recv_fifo.count <= pThis->recv_fifo.itl)
     691                ? pThis->recv_fifo.itl - pThis->recv_fifo.count : 1;
    709692        else
    710693            return 0;
    711694    } else {
    712         return !(s->lsr & UART_LSR_DR);
    713     }
    714 }
    715 
    716 static void serial_receive(void *opaque, const uint8_t *buf, int size)
    717 {
    718     SerialState *s = (SerialState*)opaque;
    719     if (s->fcr & UART_FCR_FE) {
     695        return !(pThis->lsr & UART_LSR_DR);
     696    }
     697}
     698
     699static void serial_receive(PDEVSERIAL pThis, const uint8_t *buf, int size)
     700{
     701    if (pThis->fcr & UART_FCR_FE) {
    720702        int i;
    721703        for (i = 0; i < size; i++) {
    722             fifo_put(s, RECV_FIFO, buf[i]);
    723         }
    724         s->lsr |= UART_LSR_DR;
     704            fifo_put(pThis, RECV_FIFO, buf[i]);
     705        }
     706        pThis->lsr |= UART_LSR_DR;
    725707        /* call the timeout receive callback in 4 char transmit time */
    726         TMTimerSet(s->fifo_timeout_timer, TMTimerGet(s->fifo_timeout_timer) + s->char_transmit_time * 4);
     708        TMTimerSet(pThis->fifo_timeout_timer, TMTimerGet(pThis->fifo_timeout_timer) + pThis->char_transmit_time * 4);
    727709    } else {
    728         if (s->lsr & UART_LSR_DR)
    729             s->lsr |= UART_LSR_OE;
    730         s->rbr = buf[0];
    731         s->lsr |= UART_LSR_DR;
    732     }
    733     serial_update_irq(s);
    734 }
    735 
    736 /** @copydoc PDMICHARPORT::pfnNotifyRead */
     710        if (pThis->lsr & UART_LSR_DR)
     711            pThis->lsr |= UART_LSR_OE;
     712        pThis->rbr = buf[0];
     713        pThis->lsr |= UART_LSR_DR;
     714    }
     715    serial_update_irq(pThis);
     716}
     717
     718
     719/**
     720 * @interface_method_impl{PDMICHARPORT,pfnNotifyRead}
     721 */
    737722static DECLCALLBACK(int) serialNotifyRead(PPDMICHARPORT pInterface, const void *pvBuf, size_t *pcbRead)
    738723{
    739     SerialState *pThis = PDMICHARPORT_2_SERIALSTATE(pInterface);
     724    PDEVSERIAL pThis = RT_FROM_MEMBER(pInterface, DEVSERIAL, ICharPort);
    740725    const uint8_t *pu8Buf = (const uint8_t*)pvBuf;
    741726    size_t cbRead = *pcbRead;
     
    760745}
    761746
    762 /** @copydoc PDMICHARPORT::pfnNotifyStatusLinesChanged */
     747/**
     748 * @@interface_method_impl{PDMICHARPORT,pfnNotifyStatusLinesChanged}
     749 */
    763750static DECLCALLBACK(int) serialNotifyStatusLinesChanged(PPDMICHARPORT pInterface, uint32_t newStatusLines)
    764751{
    765     SerialState *pThis = PDMICHARPORT_2_SERIALSTATE(pInterface);
     752    PDEVSERIAL pThis = RT_FROM_MEMBER(pInterface, DEVSERIAL, ICharPort);
    766753    uint8_t newMsr = 0;
    767754
     
    799786}
    800787
    801 /** @copydoc PDMICHARPORT::pfnNotifyBufferFull */
     788
     789/**
     790 * @interface_method_impl{PDMICHARPORT,pfnNotifyBufferFull}
     791 */
    802792static DECLCALLBACK(int) serialNotifyBufferFull(PPDMICHARPORT pInterface, bool fFull)
    803793{
     
    805795}
    806796
    807 /** @copydoc PDMICHARPORT::pfnNotifyBreak */
     797
     798/**
     799 * @interface_method_impl{PDMICHARPORT,pfnNotifyBreak}
     800 */
    808801static DECLCALLBACK(int) serialNotifyBreak(PPDMICHARPORT pInterface)
    809802{
    810     SerialState *pThis = PDMICHARPORT_2_SERIALSTATE(pInterface);
     803    PDEVSERIAL pThis = RT_FROM_MEMBER(pInterface, DEVSERIAL, ICharPort);
    811804
    812805    Log(("%s: pInterface=%p\n", __FUNCTION__, pInterface));
     
    822815}
    823816
    824 /**
    825  * Fifo timer functions.
     817
     818/* -=-=-=-=-=-=-=-=- Timer callbacks -=-=-=-=-=-=-=-=- */
     819
     820/**
     821 * @callback_method_tmpl{FNTMTIMERDEV, Fifo timer function.}
    826822 */
    827823static DECLCALLBACK(void) serialFifoTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    828824{
    829     SerialState *pThis = (SerialState *)pvUser;
     825    PDEVSERIAL pThis = (PDEVSERIAL)pvUser;
    830826    Assert(PDMCritSectIsOwner(&pThis->CritSect));
    831827    if (pThis->recv_fifo.count)
     
    837833
    838834/**
    839  * Transmit timer function.
     835 * @callback_method_tmpl{FNTMTIMERDEV, Transmit timer function.}
     836 *
    840837 * Just retry to transmit a character.
    841  *
    842  * @param   pTimer      The timer handle.
    843  * @param   pDevIns     The device instance.
    844  * @param   pvUser      The user pointer.
    845838 */
    846839static DECLCALLBACK(void) serialTransmitTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    847840{
    848     SerialState *pThis = (SerialState *)pvUser;
     841    PDEVSERIAL pThis = (PDEVSERIAL)pvUser;
    849842    Assert(PDMCritSectIsOwner(&pThis->CritSect));
    850843    serial_xmit(pThis, true);
    851844}
    852845
    853 /**
    854  * Reset the serial device.
    855  *
    856  * @param   pDevIns     The device instance.
    857  */
    858 static DECLCALLBACK(void) serialReset(PPDMDEVINS pDevIns)
    859 {
    860     SerialState *s = PDMINS_2_DATA(pDevIns, SerialState *);
    861 
    862     s->rbr = 0;
    863     s->ier = 0;
    864     s->iir = UART_IIR_NO_INT;
    865     s->lcr = 0;
    866     s->lsr = UART_LSR_TEMT | UART_LSR_THRE;
    867     s->msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS;
    868     /* Default to 9600 baud, 1 start bit, 8 data bits, 1 stop bit, no parity. */
    869     s->divider = 0x0C;
    870     s->mcr = UART_MCR_OUT2;
    871     s->scr = 0;
    872     s->tsr_retry = 0;
    873     uint64_t tf = TMTimerGetFreq(CTX_SUFF(s->transmit_timer));
    874     s->char_transmit_time = (tf / 9600) * 10;
    875     serial_tsr_retry_update_parameters(s, tf);
    876 
    877     fifo_clear(s, RECV_FIFO);
    878     fifo_clear(s, XMIT_FIFO);
    879 
    880     s->thr_ipending = 0;
    881     s->last_break_enable = 0;
    882 # ifdef VBOX_SERIAL_PCI
    883         PDMDevHlpPCISetIrqNoWait(s->CTX_SUFF(pDevIns), 0, 0);
    884 # else /* !VBOX_SERIAL_PCI */
    885         PDMDevHlpISASetIrqNoWait(s->CTX_SUFF(pDevIns), s->irq, 0);
    886 # endif /* !VBOX_SERIAL_PCI */
    887 }
    888 
    889846#endif /* IN_RING3 */
    890847
    891 /**
    892  * Port I/O Handler for OUT operations.
    893  *
    894  * @returns VBox status code.
    895  *
    896  * @param   pDevIns     The device instance.
    897  * @param   pvUser      User argument.
    898  * @param   Port        Port number used for the IN operation.
    899  * @param   u32         The value to output.
    900  * @param   cb          The value size in bytes.
    901  */
    902 PDMBOTHCBDECL(int) serialIOPortWrite(PPDMDEVINS pDevIns, void *pvUser,
    903                                      RTIOPORT Port, uint32_t u32, unsigned cb)
    904 {
    905     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     848/* -=-=-=-=-=-=-=-=- I/O Port Access Handlers -=-=-=-=-=-=-=-=- */
     849
     850/**
     851 * @callback_method_impl{FNIOMIOPORTOUT}
     852 */
     853PDMBOTHCBDECL(int) serialIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
     854{
     855    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    906856    int          rc;
    907857    Assert(PDMCritSectIsOwner(&pThis->CritSect));
     
    921871}
    922872
    923 /**
    924  * Port I/O Handler for IN operations.
    925  *
    926  * @returns VBox status code.
    927  *
    928  * @param   pDevIns     The device instance.
    929  * @param   pvUser      User argument.
    930  * @param   Port        Port number used for the IN operation.
    931  * @param   u32         The value to output.
    932  * @param   cb          The value size in bytes.
    933  */
    934 PDMBOTHCBDECL(int) serialIOPortRead(PPDMDEVINS pDevIns, void *pvUser,
    935                                     RTIOPORT Port, uint32_t *pu32, unsigned cb)
    936 {
    937     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     873
     874/**
     875 * @callback_method_impl{FNIOMIOPORTIN}
     876 */
     877PDMBOTHCBDECL(int) serialIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
     878{
     879    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    938880    int          rc;
    939881    Assert(PDMCritSectIsOwner(&pThis->CritSect));
     
    952894#ifdef IN_RING3
    953895
    954 /**
    955  * @copydoc FNSSMDEVLIVEEXEC
    956  */
    957 static DECLCALLBACK(int) serialLiveExec(PPDMDEVINS pDevIns,
    958                                         PSSMHANDLE pSSM,
    959                                         uint32_t uPass)
    960 {
    961     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     896/* -=-=-=-=-=-=-=-=- Saved State -=-=-=-=-=-=-=-=- */
     897
     898/**
     899 * @callback_method_tmpl{FNSSMDEVLIVEEXEC}
     900 */
     901static DECLCALLBACK(int) serialLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
     902{
     903    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    962904    SSMR3PutS32(pSSM, pThis->irq);
    963905    SSMR3PutU32(pSSM, pThis->base);
     
    965907}
    966908
    967 /**
    968  * @copydoc FNSSMDEVSAVEEXEC
    969  */
    970 static DECLCALLBACK(int) serialSaveExec(PPDMDEVINS pDevIns,
    971                                         PSSMHANDLE pSSM)
    972 {
    973     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     909
     910/**
     911 * @callback_method_tmpl{FNSSMDEVSAVEEXEC}
     912 */
     913static DECLCALLBACK(int) serialSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     914{
     915    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    974916
    975917    SSMR3PutU16(pSSM, pThis->divider);
     
    996938}
    997939
    998 /**
    999  * @copydoc FNSSMDEVLOADEXEC
    1000  */
    1001 static DECLCALLBACK(int) serialLoadExec(PPDMDEVINS pDevIns,
    1002                                         PSSMHANDLE pSSM,
    1003                                         uint32_t uVersion,
    1004                                         uint32_t uPass)
    1005 {
    1006     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     940
     941/**
     942 * @callback_method_tmpl{FNSSMDEVLOADEXEC}
     943 */
     944static DECLCALLBACK(int) serialLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     945{
     946    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    1007947
    1008948    if (uVersion == SERIAL_SAVED_STATE_VERSION_16450)
     
    10751015
    10761016
    1077 /**
    1078  * @copydoc FNPDMDEVRELOCATE
    1079  */
    1080 static DECLCALLBACK(void) serialRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    1081 {
    1082     SerialState *pThis      = PDMINS_2_DATA(pDevIns, SerialState *);
    1083     pThis->pDevInsRC        = PDMDEVINS_2_RCPTR(pDevIns);
    1084     pThis->transmit_timerRC = TMTimerRCPtr(pThis->transmit_timerR3);
    1085 }
    1086 
    10871017#ifdef VBOX_SERIAL_PCI
    1088 
    1089 static DECLCALLBACK(int) serialIOPortRegionMap(PPCIDEVICE pPciDev, /* unsigned */ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
    1090 {
    1091     SerialState *pThis = PCIDEV_2_SERIALSTATE(pPciDev);
     1018/* -=-=-=-=-=-=-=-=- PCI Device Callback(s) -=-=-=-=-=-=-=-=- */
     1019
     1020/**
     1021 * @callback_method_impl{FNPCIIOREGIONMAP}
     1022 */
     1023static DECLCALLBACK(int) serialIOPortRegionMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress,
     1024                                               uint32_t cb, PCIADDRESSSPACE enmType)
     1025{
     1026    PDEVSERIAL pThis = RT_FROM_MEMBER(pPciDev, DEVSERIAL, PciDev);
    10921027    int rc = VINF_SUCCESS;
    10931028
     
    11111046#endif /* VBOX_SERIAL_PCI */
    11121047
     1048
     1049/* -=-=-=-=-=-=-=-=- PDMIBASE on LUN#1 -=-=-=-=-=-=-=-=- */
     1050
    11131051/**
    11141052 * @interface_method_impl{PDMIBASE, pfnQueryInterface}
     
    11161054static DECLCALLBACK(void *) serialQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    11171055{
    1118     SerialState *pThis = PDMIBASE_2_SERIALSTATE(pInterface);
     1056    PDEVSERIAL pThis = RT_FROM_MEMBER(pInterface, DEVSERIAL, IBase);
    11191057    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
    11201058    PDMIBASE_RETURN_INTERFACE(pszIID, PDMICHARPORT, &pThis->ICharPort);
     
    11221060}
    11231061
    1124 /**
    1125  * Destruct a device instance.
    1126  *
    1127  * Most VM resources are freed by the VM. This callback is provided so that any non-VM
    1128  * resources can be freed correctly.
    1129  *
    1130  * @returns VBox status.
    1131  * @param   pDevIns     The device instance data.
     1062
     1063/* -=-=-=-=-=-=-=-=- PDMDEVREG -=-=-=-=-=-=-=-=- */
     1064
     1065/**
     1066 * @interface_method_impl{PDMDEVREG, pfnRelocate}
     1067 */
     1068static DECLCALLBACK(void) serialRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
     1069{
     1070    PDEVSERIAL pThis      = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
     1071    pThis->pDevInsRC        = PDMDEVINS_2_RCPTR(pDevIns);
     1072    pThis->transmit_timerRC = TMTimerRCPtr(pThis->transmit_timerR3);
     1073}
     1074
     1075
     1076/**
     1077 * @interface_method_impl{PDMDEVREG, pfnReset}
     1078 */
     1079static DECLCALLBACK(void) serialReset(PPDMDEVINS pDevIns)
     1080{
     1081    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
     1082
     1083    pThis->rbr = 0;
     1084    pThis->ier = 0;
     1085    pThis->iir = UART_IIR_NO_INT;
     1086    pThis->lcr = 0;
     1087    pThis->lsr = UART_LSR_TEMT | UART_LSR_THRE;
     1088    pThis->msr = UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS;
     1089    /* Default to 9600 baud, 1 start bit, 8 data bits, 1 stop bit, no parity. */
     1090    pThis->divider = 0x0C;
     1091    pThis->mcr = UART_MCR_OUT2;
     1092    pThis->scr = 0;
     1093    pThis->tsr_retry = 0;
     1094    uint64_t tf = TMTimerGetFreq(CTX_SUFF(pThis->transmit_timer));
     1095    pThis->char_transmit_time = (tf / 9600) * 10;
     1096    serial_tsr_retry_update_parameters(pThis, tf);
     1097
     1098    fifo_clear(pThis, RECV_FIFO);
     1099    fifo_clear(pThis, XMIT_FIFO);
     1100
     1101    pThis->thr_ipending = 0;
     1102    pThis->last_break_enable = 0;
     1103# ifdef VBOX_SERIAL_PCI
     1104        PDMDevHlpPCISetIrqNoWait(pThis->CTX_SUFF(pDevIns), 0, 0);
     1105# else /* !VBOX_SERIAL_PCI */
     1106        PDMDevHlpISASetIrqNoWait(pThis->CTX_SUFF(pDevIns), pThis->irq, 0);
     1107# endif /* !VBOX_SERIAL_PCI */
     1108}
     1109
     1110
     1111/**
     1112 * @interface_method_impl{PDMDEVREG, pfnDestruct}
    11321113 */
    11331114static DECLCALLBACK(int) serialDestruct(PPDMDEVINS pDevIns)
    11341115{
    1135     SerialState *pThis = PDMINS_2_DATA(pDevIns, SerialState *);
     1116    PDEVSERIAL pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    11361117    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    11371118
     
    11491130static DECLCALLBACK(int) serialConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    11501131{
     1132    PDEVSERIAL     pThis = PDMINS_2_DATA(pDevIns, PDEVSERIAL);
    11511133    int            rc;
    1152     SerialState   *pThis = PDMINS_2_DATA(pDevIns, SerialState*);
    11531134    uint16_t       io_base;
    11541135    uint8_t        irq_lvl;
     
    11641145    pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    11651146    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
     1147    pThis->ReceiveSem = NIL_RTSEMEVENT;
    11661148
    11671149    /* IBase */
     
    11761158#ifdef VBOX_SERIAL_PCI
    11771159    /* the PCI device */
    1178     pThis->dev.config[0x00] = 0xee; /* Vendor: ??? */
    1179     pThis->dev.config[0x01] = 0x80;
    1180     pThis->dev.config[0x02] = 0x01; /* Device: ??? */
    1181     pThis->dev.config[0x03] = 0x01;
    1182     pThis->dev.config[0x04] = PCI_COMMAND_IOACCESS;
    1183     pThis->dev.config[0x09] = 0x01; /* Programming interface: 16450 */
    1184     pThis->dev.config[0x0a] = 0x00; /* Subclass: Serial controller */
    1185     pThis->dev.config[0x0b] = 0x07; /* Class: Communication controller */
    1186     pThis->dev.config[0x0e] = 0x00; /* Header type: standard */
    1187     pThis->dev.config[0x3c] = irq_lvl; /* preconfigure IRQ number (0 = autoconfig)*/
    1188     pThis->dev.config[0x3d] = 1;    /* interrupt pin 0 */
     1160    pThis->PciDev.config[0x00] = 0xee; /* Vendor: ??? */
     1161    pThis->PciDev.config[0x01] = 0x80;
     1162    pThis->PciDev.config[0x02] = 0x01; /* Device: ??? */
     1163    pThis->PciDev.config[0x03] = 0x01;
     1164    pThis->PciDev.config[0x04] = PCI_COMMAND_IOACCESS;
     1165    pThis->PciDev.config[0x09] = 0x01; /* Programming interface: 16450 */
     1166    pThis->PciDev.config[0x0a] = 0x00; /* Subclass: Serial controller */
     1167    pThis->PciDev.config[0x0b] = 0x07; /* Class: Communication controller */
     1168    pThis->PciDev.config[0x0e] = 0x00; /* Header type: standard */
     1169    pThis->PciDev.config[0x3c] = irq_lvl; /* preconfigure IRQ number (0 = autoconfig)*/
     1170    pThis->PciDev.config[0x3d] = 1;    /* interrupt pin 0 */
    11891171#endif /* VBOX_SERIAL_PCI */
    11901172
     
    13031285     * Register the PCI Device and region.
    13041286     */
    1305     rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
     1287    rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev);
    13061288    if (RT_FAILURE(rc))
    13071289        return rc;
     
    14001382    UINT32_MAX,
    14011383    /* cbInstance */
    1402     sizeof(SerialState),
     1384    sizeof(DEVSERIAL),
    14031385    /* pfnConstruct */
    14041386    serialConstruct,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette