| [965dc18] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2008 Pavel Rimsky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup sparc64
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #ifndef KERN_sparc64_SGCN_H_
|
|---|
| 36 | #define KERN_sparc64_SGCN_H_
|
|---|
| 37 |
|
|---|
| [d99c1d2] | 38 | #include <typedefs.h>
|
|---|
| [de88998] | 39 | #include <console/chardev.h>
|
|---|
| [253d3d0] | 40 | #include <proc/thread.h>
|
|---|
| [a71c158] | 41 | #include <synch/spinlock.h>
|
|---|
| [965dc18] | 42 |
|
|---|
| [b60c582] | 43 | /* number of bytes in the TOC magic, including the NULL-terminator */
|
|---|
| [a71c158] | 44 | #define TOC_MAGIC_BYTES 8
|
|---|
| [965dc18] | 45 |
|
|---|
| [b60c582] | 46 | /* number of bytes in the TOC key, including the NULL-terminator */
|
|---|
| [a71c158] | 47 | #define TOC_KEY_SIZE 8
|
|---|
| [965dc18] | 48 |
|
|---|
| 49 | /* maximum number of entries in the SRAM table of contents */
|
|---|
| [a71c158] | 50 | #define MAX_TOC_ENTRIES 32
|
|---|
| [965dc18] | 51 |
|
|---|
| [b60c582] | 52 | /* number of bytes in the SGCN buffer magic, including the NULL-terminator */
|
|---|
| [a71c158] | 53 | #define SGCN_MAGIC_BYTES 4
|
|---|
| [965dc18] | 54 |
|
|---|
| 55 | /**
|
|---|
| 56 | * Entry in the SRAM table of contents. Describes one segment of the SRAM
|
|---|
| 57 | * which serves a particular purpose (e.g. OBP serial console, Solaris serial
|
|---|
| [a71c158] | 58 | * console, Solaris mailbox,...).
|
|---|
| [965dc18] | 59 | */
|
|---|
| 60 | typedef struct {
|
|---|
| 61 | /** key (e.g. "OBPCONS", "SOLCONS", "SOLMBOX",...) */
|
|---|
| 62 | char key[TOC_KEY_SIZE];
|
|---|
| 63 |
|
|---|
| 64 | /** size of the segment in bytes */
|
|---|
| 65 | uint32_t size;
|
|---|
| 66 |
|
|---|
| 67 | /** offset of the segment within SRAM */
|
|---|
| 68 | uint32_t offset;
|
|---|
| 69 | } __attribute ((packed)) toc_entry_t;
|
|---|
| 70 |
|
|---|
| 71 | /**
|
|---|
| 72 | * SRAM table of contents. Describes all segments within the SRAM.
|
|---|
| 73 | */
|
|---|
| 74 | typedef struct {
|
|---|
| 75 | /** hard-wired to "TOCSRAM" */
|
|---|
| 76 | char magic[TOC_MAGIC_BYTES];
|
|---|
| 77 |
|
|---|
| 78 | /** we don't need this */
|
|---|
| 79 | char unused[8];
|
|---|
| 80 |
|
|---|
| 81 | /** TOC entries */
|
|---|
| 82 | toc_entry_t keys[MAX_TOC_ENTRIES];
|
|---|
| 83 | } __attribute__ ((packed)) iosram_toc_t;
|
|---|
| 84 |
|
|---|
| 85 | /**
|
|---|
| 86 | * SGCN buffer header. It is placed at the very beginning of the SGCN
|
|---|
| [a71c158] | 87 | * buffer.
|
|---|
| [965dc18] | 88 | */
|
|---|
| 89 | typedef struct {
|
|---|
| 90 | /** hard-wired to "CON" */
|
|---|
| 91 | char magic[SGCN_MAGIC_BYTES];
|
|---|
| 92 |
|
|---|
| 93 | /** we don't need this */
|
|---|
| 94 | char unused[8];
|
|---|
| 95 |
|
|---|
| 96 | /** offset within the SGCN buffer of the input buffer start */
|
|---|
| 97 | uint32_t in_begin;
|
|---|
| 98 |
|
|---|
| 99 | /** offset within the SGCN buffer of the input buffer end */
|
|---|
| 100 | uint32_t in_end;
|
|---|
| 101 |
|
|---|
| 102 | /** offset within the SGCN buffer of the input buffer read pointer */
|
|---|
| 103 | uint32_t in_rdptr;
|
|---|
| 104 |
|
|---|
| 105 | /** offset within the SGCN buffer of the input buffer write pointer */
|
|---|
| 106 | uint32_t in_wrptr;
|
|---|
| [a71c158] | 107 |
|
|---|
| [965dc18] | 108 | /** offset within the SGCN buffer of the output buffer start */
|
|---|
| 109 | uint32_t out_begin;
|
|---|
| 110 |
|
|---|
| 111 | /** offset within the SGCN buffer of the output buffer end */
|
|---|
| 112 | uint32_t out_end;
|
|---|
| 113 |
|
|---|
| 114 | /** offset within the SGCN buffer of the output buffer read pointer */
|
|---|
| 115 | uint32_t out_rdptr;
|
|---|
| 116 |
|
|---|
| 117 | /** offset within the SGCN buffer of the output buffer write pointer */
|
|---|
| 118 | uint32_t out_wrptr;
|
|---|
| 119 | } __attribute__ ((packed)) sgcn_buffer_header_t;
|
|---|
| 120 |
|
|---|
| [253d3d0] | 121 | typedef struct {
|
|---|
| [a71c158] | 122 | /** Starting address of SRAM */
|
|---|
| 123 | uintptr_t sram_begin;
|
|---|
| 124 |
|
|---|
| 125 | /** Starting address of the SGCN buffer */
|
|---|
| 126 | uintptr_t buffer_begin;
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * Ensure that writing to the buffer and consequent
|
|---|
| 130 | * update of the write pointer are one atomic operation.
|
|---|
| 131 | */
|
|---|
| 132 | SPINLOCK_DECLARE(output_lock);
|
|---|
| 133 |
|
|---|
| 134 | /**
|
|---|
| 135 | * Prevent the input buffer read/write pointers from
|
|---|
| 136 | * getting to inconsistent state.
|
|---|
| 137 | */
|
|---|
| 138 | SPINLOCK_DECLARE(input_lock);
|
|---|
| 139 |
|
|---|
| [253d3d0] | 140 | thread_t *thread;
|
|---|
| 141 | indev_t *srlnin;
|
|---|
| 142 | } sgcn_instance_t;
|
|---|
| 143 |
|
|---|
| 144 | extern sgcn_instance_t *sgcnin_init(void);
|
|---|
| 145 | extern void sgcnin_wire(sgcn_instance_t *, indev_t *);
|
|---|
| [a71c158] | 146 | extern outdev_t *sgcnout_init(void);
|
|---|
| [965dc18] | 147 |
|
|---|
| 148 | #endif
|
|---|
| 149 |
|
|---|
| 150 | /** @}
|
|---|
| 151 | */
|
|---|