Changeset 3c79afe in mainline
- Timestamp:
- 2009-03-12T17:54:24Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3a1c048
- Parents:
- a0e1b48
- Location:
- kernel/genarch
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/include/drivers/i8042/i8042.h
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 41 41 #include <typedefs.h> 42 42 43 struct i8042{43 typedef struct { 44 44 ioport8_t data; 45 45 uint8_t pad[3]; 46 46 ioport8_t status; 47 } __attribute__ ((packed)); 48 typedef struct i8042 i8042_t; 47 } __attribute__ ((packed)) i8042_t; 49 48 50 typedef struct i8042_instance{49 typedef struct { 51 50 devno_t devno; 52 51 irq_t irq; 53 52 i8042_t *i8042; 54 chardev_t *devout;53 indev_t kbrdin; 55 54 } i8042_instance_t; 56 55 57 extern bool i8042_init(i8042_t *, devno_t, inr_t, chardev_t *);56 extern indev_t *i8042_init(i8042_t *, devno_t, inr_t); 58 57 59 58 #endif -
kernel/genarch/include/drivers/ns16550/ns16550.h
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Headers for NS 16550 serial controller. 35 35 */ 36 36 … … 42 42 #include <console/chardev.h> 43 43 44 #define IER_ERBFI 0x01/** Enable Receive Buffer Full Interrupt. */44 #define IER_ERBFI 0x01 /** Enable Receive Buffer Full Interrupt. */ 45 45 46 #define LCR_DLAB 0x80/** Divisor Latch Access bit. */46 #define LCR_DLAB 0x80 /** Divisor Latch Access bit. */ 47 47 48 #define MCR_OUT2 0x08/** OUT2. */48 #define MCR_OUT2 0x08 /** OUT2. */ 49 49 50 50 /** NS16550 registers. */ 51 struct ns16550{52 ioport8_t rbr; 53 ioport8_t ier; 51 typedef struct { 52 ioport8_t rbr; /**< Receiver Buffer Register. */ 53 ioport8_t ier; /**< Interrupt Enable Register. */ 54 54 union { 55 ioport8_t iir; 56 ioport8_t fcr; 55 ioport8_t iir; /**< Interrupt Ident Register (read). */ 56 ioport8_t fcr; /**< FIFO control register (write). */ 57 57 } __attribute__ ((packed)); 58 ioport8_t lcr; /**< Line Control register. */ 59 ioport8_t mcr; /**< Modem Control Register. */ 60 ioport8_t lsr; /**< Line Status Register. */ 61 } __attribute__ ((packed)); 62 typedef struct ns16550 ns16550_t; 58 ioport8_t lcr; /**< Line Control register. */ 59 ioport8_t mcr; /**< Modem Control Register. */ 60 ioport8_t lsr; /**< Line Status Register. */ 61 } __attribute__ ((packed)) ns16550_t; 63 62 64 63 /** Structure representing the ns16550 device. */ 65 typedef struct ns16550_instance{64 typedef struct { 66 65 devno_t devno; 67 66 ns16550_t *ns16550; 68 67 irq_t irq; 69 chardev_t *devout;68 indev_t kbrdin; 70 69 } ns16550_instance_t; 71 70 72 extern bool ns16550_init(ns16550_t *, devno_t, inr_t, cir_t, void *, 73 chardev_t *); 74 extern irq_ownership_t ns16550_claim(irq_t *); 75 extern void ns16550_irq_handler(irq_t *); 71 extern indev_t *ns16550_init(ns16550_t *, devno_t, inr_t, cir_t, void *) 76 72 77 73 #endif -
kernel/genarch/include/drivers/z8530/z8530.h
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Headers for Zilog 8530 serial controller. 35 35 */ 36 36 … … 42 42 #include <console/chardev.h> 43 43 44 #define WR0 45 #define WR1 46 #define WR2 47 #define WR3 48 #define WR4 49 #define WR5 50 #define WR6 51 #define WR7 52 #define WR8 53 #define WR9 54 #define WR10 55 #define WR11 56 #define WR12 57 #define WR13 58 #define WR14 59 #define WR15 44 #define WR0 0 45 #define WR1 1 46 #define WR2 2 47 #define WR3 3 48 #define WR4 4 49 #define WR5 5 50 #define WR6 6 51 #define WR7 7 52 #define WR8 8 53 #define WR9 9 54 #define WR10 10 55 #define WR11 11 56 #define WR12 12 57 #define WR13 13 58 #define WR14 14 59 #define WR15 15 60 60 61 #define RR0 62 #define RR1 63 #define RR2 64 #define RR3 65 #define RR8 66 #define RR10 67 #define RR12 68 #define RR13 69 #define RR14 70 #define RR15 61 #define RR0 0 62 #define RR1 1 63 #define RR2 2 64 #define RR3 3 65 #define RR8 8 66 #define RR10 10 67 #define RR12 12 68 #define RR13 13 69 #define RR14 14 70 #define RR15 15 71 71 72 72 /** Reset pending TX interrupt. */ 73 #define WR0_TX_IP_RST 74 #define WR0_ERR_RST 73 #define WR0_TX_IP_RST (0x5 << 3) 74 #define WR0_ERR_RST (0x6 << 3) 75 75 76 76 /** Receive Interrupts Disabled. */ 77 #define WR1_RID 77 #define WR1_RID (0x0 << 3) 78 78 /** Receive Interrupt on First Character or Special Condition. */ 79 #define WR1_RIFCSC 79 #define WR1_RIFCSC (0x1 << 3) 80 80 /** Interrupt on All Receive Characters or Special Conditions. */ 81 #define WR1_IARCSC 81 #define WR1_IARCSC (0x2 << 3) 82 82 /** Receive Interrupt on Special Condition. */ 83 #define WR1_RISC 83 #define WR1_RISC (0x3 << 3) 84 84 /** Parity Is Special Condition. */ 85 #define WR1_PISC 85 #define WR1_PISC (0x1 << 2) 86 86 87 87 /** Rx Enable. */ 88 #define WR3_RX_ENABLE 88 #define WR3_RX_ENABLE (0x1 << 0) 89 89 /** 8-bits per character. */ 90 #define WR3_RX8BITSCH 90 #define WR3_RX8BITSCH (0x3 << 6) 91 91 92 92 /** Master Interrupt Enable. */ 93 #define WR9_MIE 93 #define WR9_MIE (0x1 << 3) 94 94 95 95 /** Receive Character Available. */ 96 #define RR0_RCA 96 #define RR0_RCA (0x1 << 0) 97 97 98 98 /** z8530's registers. */ 99 struct z8530{99 typedef struct { 100 100 union { 101 101 ioport8_t ctl_b; … … 111 111 uint8_t pad3; 112 112 ioport8_t data_a; 113 } __attribute__ ((packed)); 114 typedef struct z8530 z8530_t; 113 } __attribute__ ((packed)) z8530_t; 115 114 116 115 /** Structure representing the z8530 device. */ … … 119 118 irq_t irq; 120 119 z8530_t *z8530; 121 chardev_t *devout;120 indev_t kbrdin; 122 121 } z8530_instance_t; 123 122 124 extern bool z8530_init(z8530_t *, devno_t, inr_t, cir_t, void *, chardev_t *); 125 extern irq_ownership_t z8530_claim(irq_t *); 126 extern void z8530_irq_handler(irq_t *); 123 extern devin_t *z8530_init(z8530_t *, devno_t, inr_t, cir_t, void *); 127 124 128 125 #endif -
kernel/genarch/src/drivers/i8042/i8042.c
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief 34 * @brief i8042 processor driver 35 35 * 36 36 * It takes care of the i8042 serial communication. … … 43 43 #include <mm/slab.h> 44 44 45 #define i8042_SET_COMMAND 0x60 46 #define i8042_COMMAND 0x69 45 indev_operations_t kbrdin_ops = { 46 .poll = NULL 47 }; 47 48 48 #define i8042_BUFFER_FULL_MASK 0x01 49 #define i8042_WAIT_MASK 0x02 49 #define i8042_SET_COMMAND 0x60 50 #define i8042_COMMAND 0x69 51 52 #define i8042_BUFFER_FULL_MASK 0x01 53 #define i8042_WAIT_MASK 0x02 50 54 51 55 static irq_ownership_t i8042_claim(irq_t *irq) … … 53 57 i8042_instance_t *i8042_instance = irq->instance; 54 58 i8042_t *dev = i8042_instance->i8042; 59 55 60 if (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK) 56 61 return IRQ_ACCEPT; … … 63 68 i8042_instance_t *instance = irq->instance; 64 69 i8042_t *dev = instance->i8042; 65 66 uint8_t data;67 70 uint8_t status; 68 71 69 72 if (((status = pio_read_8(&dev->status)) & i8042_BUFFER_FULL_MASK)) { 70 data = pio_read_8(&dev->data); 71 72 if (instance->devout) 73 chardev_push_character(instance->devout, data); 73 uint8_t data = pio_read_8(&dev->data); 74 indev_push_character(&instance->kbrdin, data); 74 75 } 75 76 } 76 77 77 78 /** Initialize i8042. */ 78 bool 79 i8042_init(i8042_t *dev, devno_t devno, inr_t inr, chardev_t *devout) 79 indev_t *i8042_init(i8042_t *dev, devno_t devno, inr_t inr) 80 80 { 81 i8042_instance_t *instance; 82 83 instance = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC); 81 i8042_instance_t *instance 82 = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC); 84 83 if (!instance) 85 return false; 84 return NULL; 85 86 indev_initialize("i8042", &instance->kbrdin, &kbrdin_ops); 86 87 87 88 instance->devno = devno; 88 89 instance->i8042 = dev; 89 instance->devout = devout;90 90 91 91 irq_initialize(&instance->irq); … … 103 103 (void) pio_read_8(&dev->data); 104 104 105 return true;105 return &instance->kbrdin; 106 106 } 107 107 -
kernel/genarch/src/drivers/ns16550/ns16550.c
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief 34 * @brief NS 16550 serial controller driver. 35 35 */ 36 36 … … 41 41 #include <mm/slab.h> 42 42 43 #define LSR_DATA_READY 0x01 43 #define LSR_DATA_READY 0x01 44 45 indev_operations_t kbrdin_ops = { 46 .poll = NULL 47 }; 48 49 static irq_ownership_t ns16550_claim(irq_t *irq) 50 { 51 ns16550_instance_t *instance = irq->instance; 52 ns16550_t *dev = instance->ns16550; 53 54 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) 55 return IRQ_ACCEPT; 56 else 57 return IRQ_DECLINE; 58 } 59 60 static void ns16550_irq_handler(irq_t *irq) 61 { 62 ns16550_instance_t *instance = irq->instance; 63 ns16550_t *dev = instance->ns16550; 64 65 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { 66 uint8_t x = pio_read_8(&dev->rbr); 67 chardev_push_character(&instance->kbrdin, x); 68 } 69 } 44 70 45 71 /** Initialize ns16550. 46 72 * 47 * @param dev Addrress of the beginning of the device in I/O space. 48 * @param devno Device number. 49 * @param inr Interrupt number. 50 * @param cir Clear interrupt function. 51 * @param cir_arg First argument to cir. 52 * @param devout Output character device. 73 * @param dev Addrress of the beginning of the device in I/O space. 74 * @param devno Device number. 75 * @param inr Interrupt number. 76 * @param cir Clear interrupt function. 77 * @param cir_arg First argument to cir. 53 78 * 54 * @return True on success, false on failure. 79 * @return Keyboard device pointer or NULL on failure. 80 * 55 81 */ 56 bool 57 ns16550_init(ns16550_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg, 58 chardev_t *devout) 82 indev_t *ns16550_init(ns16550_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg) 59 83 { 60 ns16550_instance_t *instance; 84 ns16550_instance_t *instance 85 = malloc(sizeof(ns16550_instance_t), FRAME_ATOMIC); 86 if (!instance) 87 return NULL; 61 88 62 instance = malloc(sizeof(ns16550_instance_t), FRAME_ATOMIC); 63 if (!instance) 64 return false; 65 89 indev_initialize("ns16550", &instance->kbrdin, &kbrdin_ops); 90 66 91 instance->devno = devno; 67 92 instance->ns16550 = dev; 68 instance->devout = devout;69 93 70 94 irq_initialize(&instance->irq); … … 77 101 instance->irq.cir_arg = cir_arg; 78 102 irq_register(&instance->irq); 79 103 80 104 while ((pio_read_8(&dev->lsr) & LSR_DATA_READY)) 81 105 (void) pio_read_8(&dev->rbr); … … 85 109 pio_write_8(&dev->mcr, MCR_OUT2); 86 110 87 return true; 88 } 89 90 irq_ownership_t ns16550_claim(irq_t *irq) 91 { 92 ns16550_instance_t *instance = irq->instance; 93 ns16550_t *dev = instance->ns16550; 94 95 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) 96 return IRQ_ACCEPT; 97 else 98 return IRQ_DECLINE; 99 } 100 101 void ns16550_irq_handler(irq_t *irq) 102 { 103 ns16550_instance_t *instance = irq->instance; 104 ns16550_t *dev = instance->ns16550; 105 106 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { 107 uint8_t x; 108 109 x = pio_read_8(&dev->rbr); 110 if (instance->devout) 111 chardev_push_character(instance->devout, x); 112 } 111 return &instance->kbrdin; 113 112 } 114 113 -
kernel/genarch/src/drivers/z8530/z8530.c
ra0e1b48 r3c79afe 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Zilog 8530 serial controller driver. 35 35 */ 36 36 … … 41 41 #include <mm/slab.h> 42 42 43 indev_operations_t kbrdin_ops = { 44 .poll = NULL 45 }; 46 43 47 static inline void z8530_write(ioport8_t *ctl, uint8_t reg, uint8_t val) 44 48 { … … 47 51 * command as their bit 3 is 1. 48 52 */ 49 pio_write_8(ctl, reg); /* select register */50 pio_write_8(ctl, val); /* write value */53 pio_write_8(ctl, reg); /* Select register */ 54 pio_write_8(ctl, val); /* Write value */ 51 55 } 52 56 … … 57 61 * command as their bit 3 is 1. 58 62 */ 59 pio_write_8(ctl, reg); /* select register */63 pio_write_8(ctl, reg); /* Select register */ 60 64 return pio_read_8(ctl); 61 65 } 62 66 67 static irq_ownership_t z8530_claim(irq_t *irq) 68 { 69 z8530_instance_t *instance = irq->instance; 70 z8530_t *dev = instance->z8530; 71 72 if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) 73 return IRQ_ACCEPT; 74 else 75 return IRQ_DECLINE; 76 } 77 78 static void z8530_irq_handler(irq_t *irq) 79 { 80 z8530_instance_t *instance = irq->instance; 81 z8530_t *dev = instance->z8530; 82 83 if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) { 84 uint8_t x = z8530_read(&dev->ctl_a, RR8); 85 chardev_push_character(&instance->kbrdin, x); 86 } 87 } 88 63 89 /** Initialize z8530. */ 64 bool 65 z8530_init(z8530_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg, 66 chardev_t *devout) 90 indev_t *z8530_init(z8530_t *dev, devno_t devno, inr_t inr, cir_t cir, void *cir_arg) 67 91 { 68 z8530_instance_t *instance; 69 70 instance = malloc(sizeof(z8530_instance_t), FRAME_ATOMIC); 92 z8530_instance_t *instance 93 = malloc(sizeof(z8530_instance_t), FRAME_ATOMIC); 71 94 if (!instance) 72 95 return false; 73 96 97 indev_initialize("z8530", &instance->kbrdin, &kbrdin_ops); 98 74 99 instance->devno = devno; 75 100 instance->z8530 = dev; 76 instance->devout = devout; 77 101 78 102 irq_initialize(&instance->irq); 79 103 instance->irq.devno = devno; … … 85 109 instance->irq.cir_arg = cir_arg; 86 110 irq_register(&instance->irq); 87 111 88 112 (void) z8530_read(&dev->ctl_a, RR8); 89 113 90 114 /* 91 115 * Clear any pending TX interrupts or we never manage … … 93 117 */ 94 118 z8530_write(&dev->ctl_a, WR0, WR0_TX_IP_RST); 95 119 96 120 /* interrupt on all characters */ 97 121 z8530_write(&dev->ctl_a, WR1, WR1_IARCSC); 98 122 99 123 /* 8 bits per character and enable receiver */ 100 124 z8530_write(&dev->ctl_a, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); … … 102 126 /* Master Interrupt Enable. */ 103 127 z8530_write(&dev->ctl_a, WR9, WR9_MIE); 104 105 return true; 106 } 107 108 irq_ownership_t z8530_claim(irq_t *irq) 109 { 110 z8530_instance_t *instance = irq->instance; 111 z8530_t *dev = instance->z8530; 112 113 if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) 114 return IRQ_ACCEPT; 115 else 116 return IRQ_DECLINE; 117 } 118 119 void z8530_irq_handler(irq_t *irq) 120 { 121 z8530_instance_t *instance = irq->instance; 122 z8530_t *dev = instance->z8530; 123 uint8_t x; 124 125 if (z8530_read(&dev->ctl_a, RR0) & RR0_RCA) { 126 x = z8530_read(&dev->ctl_a, RR8); 127 if (instance->devout) 128 chardev_push_character(instance->devout, x); 129 } 128 129 return &instance->kbrdin; 130 130 } 131 131
Note:
See TracChangeset
for help on using the changeset viewer.