Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef STICORE_H
0003 #define STICORE_H
0004 
0005 /* generic STI structures & functions */
0006 
0007 #define MAX_STI_ROMS 4      /* max no. of ROMs which this driver handles */
0008 
0009 #define STI_REGION_MAX 8    /* hardcoded STI constants */
0010 #define STI_DEV_NAME_LENGTH 32
0011 #define STI_MONITOR_MAX 256
0012 
0013 #define STI_FONT_HPROMAN8 1
0014 #define STI_FONT_KANA8 2
0015 
0016 #define ALT_CODE_TYPE_UNKNOWN 0x00  /* alt code type values */
0017 #define ALT_CODE_TYPE_PA_RISC_64 0x01
0018 
0019 /* The latency of the STI functions cannot really be reduced by setting
0020  * this to 0;  STI doesn't seem to be designed to allow calling a different
0021  * function (or the same function with different arguments) after a
0022  * function exited with 1 as return value.
0023  *
0024  * As all of the functions below could be called from interrupt context,
0025  * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
0026  * block.  Really bad latency there.
0027  *
0028  * Probably the best solution to all this is have the generic code manage
0029  * the screen buffer and a kernel thread to call STI occasionally.
0030  * 
0031  * Luckily, the frame buffer guys have the same problem so we can just wait
0032  * for them to fix it and steal their solution.   prumpf
0033  */
0034  
0035 #include <asm/io.h>
0036 
0037 #define STI_WAIT 1
0038 
0039 #define STI_PTR(p)  ( virt_to_phys(p) )
0040 #define PTR_STI(p)  ( phys_to_virt((unsigned long)p) )
0041 
0042 #define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
0043 #define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
0044 
0045 /* sti_font_xy() use the native font ROM ! */
0046 #define sti_font_x(sti) (PTR_STI(sti->font)->width)
0047 #define sti_font_y(sti) (PTR_STI(sti->font)->height)
0048 
0049 #ifdef CONFIG_64BIT
0050 #define STI_LOWMEM  (GFP_KERNEL | GFP_DMA)
0051 #else
0052 #define STI_LOWMEM  (GFP_KERNEL)
0053 #endif
0054 
0055 
0056 /* STI function configuration structs */
0057 
0058 typedef union region {
0059     struct { 
0060         u32 offset  : 14;   /* offset in 4kbyte page */
0061         u32 sys_only    : 1;    /* don't map to user space */
0062         u32 cache   : 1;    /* map to data cache */
0063         u32 btlb    : 1;    /* map to block tlb */
0064         u32 last    : 1;    /* last region in list */
0065         u32 length  : 14;   /* length in 4kbyte page */
0066     } region_desc;
0067 
0068     u32 region;         /* complete region value */
0069 } region_t;
0070 
0071 #define REGION_OFFSET_TO_PHYS( rt, hpa ) \
0072     (((rt).region_desc.offset << 12) + (hpa))
0073 
0074 struct sti_glob_cfg_ext {
0075      u8 curr_mon;           /* current monitor configured */
0076      u8 friendly_boot;      /* in friendly boot mode */
0077     s16 power;          /* power calculation (in Watts) */
0078     s32 freq_ref;           /* frequency reference */
0079     u32 sti_mem_addr;       /* pointer to global sti memory (size=sti_mem_request) */
0080     u32 future_ptr;         /* pointer to future data */
0081 };
0082 
0083 struct sti_glob_cfg {
0084     s32 text_planes;        /* number of planes used for text */
0085     s16 onscreen_x;         /* screen width in pixels */
0086     s16 onscreen_y;         /* screen height in pixels */
0087     s16 offscreen_x;        /* offset width in pixels */
0088     s16 offscreen_y;        /* offset height in pixels */
0089     s16 total_x;            /* frame buffer width in pixels */
0090     s16 total_y;            /* frame buffer height in pixels */
0091     u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
0092     s32 reent_lvl;          /* storage for reentry level value */
0093     u32 save_addr;          /* where to save or restore reentrant state */
0094     u32 ext_ptr;            /* pointer to extended glob_cfg data structure */
0095 };
0096 
0097 
0098 /* STI init function structs */
0099 
0100 struct sti_init_flags {
0101     u32 wait : 1;       /* should routine idle wait or not */
0102     u32 reset : 1;      /* hard reset the device? */
0103     u32 text : 1;       /* turn on text display planes? */
0104     u32 nontext : 1;    /* turn on non-text display planes? */
0105     u32 clear : 1;      /* clear text display planes? */
0106     u32 cmap_blk : 1;   /* non-text planes cmap black? */
0107     u32 enable_be_timer : 1; /* enable bus error timer */
0108     u32 enable_be_int : 1;  /* enable bus error timer interrupt */
0109     u32 no_chg_tx : 1;  /* don't change text settings */
0110     u32 no_chg_ntx : 1; /* don't change non-text settings */
0111     u32 no_chg_bet : 1; /* don't change berr timer settings */
0112     u32 no_chg_bei : 1; /* don't change berr int settings */
0113     u32 init_cmap_tx : 1;   /* initialize cmap for text planes */
0114     u32 cmt_chg : 1;    /* change current monitor type */
0115     u32 retain_ie : 1;  /* don't allow reset to clear int enables */
0116     u32 caller_bootrom : 1; /* set only by bootrom for each call */
0117     u32 caller_kernel : 1;  /* set only by kernel for each call */
0118     u32 caller_other : 1;   /* set only by non-[BR/K] caller */
0119     u32 pad : 14;       /* pad to word boundary */
0120     u32 future_ptr;     /* pointer to future data */
0121 };
0122 
0123 struct sti_init_inptr_ext {
0124     u8  config_mon_type;    /* configure to monitor type */
0125     u8  pad[1];     /* pad to word boundary */
0126     u16 inflight_data;  /* inflight data possible on PCI */
0127     u32 future_ptr;     /* pointer to future data */
0128 };
0129 
0130 struct sti_init_inptr {
0131     s32 text_planes;    /* number of planes to use for text */
0132     u32 ext_ptr;        /* pointer to extended init_graph inptr data structure*/
0133 };
0134 
0135 
0136 struct sti_init_outptr {
0137     s32 errno;      /* error number on failure */
0138     s32 text_planes;    /* number of planes used for text */
0139     u32 future_ptr;     /* pointer to future data */
0140 };
0141 
0142 
0143 
0144 /* STI configuration function structs */
0145 
0146 struct sti_conf_flags {
0147     u32 wait : 1;       /* should routine idle wait or not */
0148     u32 pad : 31;       /* pad to word boundary */
0149     u32 future_ptr;     /* pointer to future data */
0150 };
0151 
0152 struct sti_conf_inptr {
0153     u32 future_ptr;     /* pointer to future data */
0154 };
0155 
0156 struct sti_conf_outptr_ext {
0157     u32 crt_config[3];  /* hardware specific X11/OGL information */ 
0158     u32 crt_hdw[3];
0159     u32 future_ptr;
0160 };
0161 
0162 struct sti_conf_outptr {
0163     s32 errno;      /* error number on failure */
0164     s16 onscreen_x;     /* screen width in pixels */
0165     s16 onscreen_y;     /* screen height in pixels */
0166     s16 offscreen_x;    /* offscreen width in pixels */
0167     s16 offscreen_y;    /* offscreen height in pixels */
0168     s16 total_x;        /* frame buffer width in pixels */
0169     s16 total_y;        /* frame buffer height in pixels */
0170     s32 bits_per_pixel; /* bits/pixel device has configured */
0171     s32 bits_used;      /* bits which can be accessed */
0172     s32 planes;     /* number of fb planes in system */
0173      u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
0174     u32 attributes;     /* flags denoting attributes */
0175     u32 ext_ptr;        /* pointer to future data */
0176 };
0177 
0178 struct sti_rom {
0179      u8 type[4];
0180      u8 res004;
0181      u8 num_mons;
0182      u8 revno[2];
0183     u32 graphics_id[2];
0184 
0185     u32 font_start;
0186     u32 statesize;
0187     u32 last_addr;
0188     u32 region_list;
0189 
0190     u16 reentsize;
0191     u16 maxtime;
0192     u32 mon_tbl_addr;
0193     u32 user_data_addr;
0194     u32 sti_mem_req;
0195 
0196     u32 user_data_size;
0197     u16 power;
0198      u8 bus_support;
0199      u8 ext_bus_support;
0200      u8 alt_code_type;
0201      u8 ext_dd_struct[3];
0202     u32 cfb_addr;
0203 
0204     u32 init_graph;
0205     u32 state_mgmt;
0206     u32 font_unpmv;
0207     u32 block_move;
0208     u32 self_test;
0209     u32 excep_hdlr;
0210     u32 inq_conf;
0211     u32 set_cm_entry;
0212     u32 dma_ctrl;
0213      u8 res040[7 * 4];
0214     
0215     u32 init_graph_addr;
0216     u32 state_mgmt_addr;
0217     u32 font_unp_addr;
0218     u32 block_move_addr;
0219     u32 self_test_addr;
0220     u32 excep_hdlr_addr;
0221     u32 inq_conf_addr;
0222     u32 set_cm_entry_addr;
0223     u32 image_unpack_addr;
0224     u32 pa_risx_addrs[7];
0225 };
0226 
0227 struct sti_rom_font {
0228     u16 first_char;
0229     u16 last_char;
0230      u8 width;
0231      u8 height;
0232      u8 font_type;      /* language type */
0233      u8 bytes_per_char;
0234     u32 next_font;
0235      u8 underline_height;
0236      u8 underline_pos;
0237      u8 res008[2];
0238 };
0239 
0240 /* sticore internal font handling */
0241 
0242 struct sti_cooked_font {
0243     struct sti_rom_font *raw;   /* native ptr for STI functions */
0244     void *raw_ptr;          /* kmalloc'ed font data */
0245     struct sti_cooked_font *next_font;
0246     int height, width;
0247     int refcount;
0248     u32 crc;
0249 };
0250 
0251 struct sti_cooked_rom {
0252         struct sti_rom *raw;
0253     struct sti_cooked_font *font_start;
0254 };
0255 
0256 /* STI font printing function structs */
0257 
0258 struct sti_font_inptr {
0259     u32 font_start_addr;    /* address of font start */
0260     s16 index;      /* index into font table of character */
0261     u8 fg_color;        /* foreground color of character */
0262     u8 bg_color;        /* background color of character */
0263     s16 dest_x;     /* X location of character upper left */
0264     s16 dest_y;     /* Y location of character upper left */
0265     u32 future_ptr;     /* pointer to future data */
0266 };
0267 
0268 struct sti_font_flags {
0269     u32 wait : 1;       /* should routine idle wait or not */
0270     u32 non_text : 1;   /* font unpack/move in non_text planes =1, text =0 */
0271     u32 pad : 30;       /* pad to word boundary */
0272     u32 future_ptr;     /* pointer to future data */
0273 };
0274     
0275 struct sti_font_outptr {
0276     s32 errno;      /* error number on failure */
0277     u32 future_ptr;     /* pointer to future data */
0278 };
0279 
0280 /* STI blockmove structs */
0281 
0282 struct sti_blkmv_flags {
0283     u32 wait : 1;       /* should routine idle wait or not */
0284     u32 color : 1;      /* change color during move? */
0285     u32 clear : 1;      /* clear during move? */
0286     u32 non_text : 1;   /* block move in non_text planes =1, text =0 */
0287     u32 pad : 28;       /* pad to word boundary */
0288     u32 future_ptr;     /* pointer to future data */
0289 };
0290 
0291 struct sti_blkmv_inptr {
0292     u8 fg_color;        /* foreground color after move */
0293     u8 bg_color;        /* background color after move */
0294     s16 src_x;      /* source upper left pixel x location */
0295     s16 src_y;      /* source upper left pixel y location */
0296     s16 dest_x;     /* dest upper left pixel x location */
0297     s16 dest_y;     /* dest upper left pixel y location */
0298     s16 width;      /* block width in pixels */
0299     s16 height;     /* block height in pixels */
0300     u32 future_ptr;     /* pointer to future data */
0301 };
0302 
0303 struct sti_blkmv_outptr {
0304     s32 errno;      /* error number on failure */
0305     u32 future_ptr;     /* pointer to future data */
0306 };
0307 
0308 
0309 /* sti_all_data is an internal struct which needs to be allocated in
0310  * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
0311 
0312 struct sti_all_data {
0313     struct sti_glob_cfg glob_cfg;
0314     struct sti_glob_cfg_ext glob_cfg_ext;
0315 
0316     struct sti_conf_inptr       inq_inptr;
0317     struct sti_conf_outptr      inq_outptr; /* configuration */
0318     struct sti_conf_outptr_ext  inq_outptr_ext;
0319 
0320     struct sti_init_inptr_ext   init_inptr_ext;
0321     struct sti_init_inptr       init_inptr;
0322     struct sti_init_outptr      init_outptr;
0323 
0324     struct sti_blkmv_inptr      blkmv_inptr;
0325     struct sti_blkmv_outptr     blkmv_outptr;
0326 
0327     struct sti_font_inptr       font_inptr;
0328     struct sti_font_outptr      font_outptr;
0329 
0330     /* leave as last entries */
0331     unsigned long save_addr[1024 / sizeof(unsigned long)];
0332        /* min 256 bytes which is STI default, max sti->sti_mem_request */
0333     unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
0334     /* do not add something below here ! */
0335 };
0336 
0337 /* internal generic STI struct */
0338 
0339 struct sti_struct {
0340     spinlock_t lock;
0341         
0342     /* char **mon_strings; */
0343     int sti_mem_request;
0344     u32 graphics_id[2];
0345 
0346     struct sti_cooked_rom *rom;
0347 
0348     unsigned long font_unpmv;
0349     unsigned long block_move;
0350     unsigned long init_graph;
0351     unsigned long inq_conf;
0352 
0353     /* all following fields are initialized by the generic routines */
0354     int text_planes;
0355     region_t regions[STI_REGION_MAX];
0356     unsigned long regions_phys[STI_REGION_MAX];
0357 
0358     struct sti_glob_cfg *glob_cfg;  /* points into sti_all_data */
0359 
0360     int wordmode;
0361     struct sti_cooked_font *font;   /* ptr to selected font (cooked) */
0362 
0363     struct pci_dev *pd;
0364 
0365     /* PCI data structures (pg. 17ff from sti.pdf) */
0366     u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
0367 
0368     /* pointer to the fb_info where this STI device is used */
0369     struct fb_info *info;
0370 
0371     /* pointer to all internal data */
0372     struct sti_all_data *sti_data;
0373 
0374     /* pa_path of this device */
0375     char pa_path[24];
0376 };
0377 
0378 
0379 /* sticore interface functions */
0380 
0381 struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
0382 void sti_font_convert_bytemode(struct sti_struct *sti, struct sti_cooked_font *f);
0383 
0384 
0385 /* sticore main function to call STI firmware */
0386 
0387 int sti_call(const struct sti_struct *sti, unsigned long func,
0388         const void *flags, void *inptr, void *outptr,
0389         struct sti_glob_cfg *glob_cfg);
0390 
0391 
0392 /* functions to call the STI ROM directly */
0393 
0394 void sti_putc(struct sti_struct *sti, int c, int y, int x,
0395         struct sti_cooked_font *font);
0396 void sti_set(struct sti_struct *sti, int src_y, int src_x,
0397         int height, int width, u8 color);
0398 void sti_clear(struct sti_struct *sti, int src_y, int src_x,
0399         int height, int width, int c, struct sti_cooked_font *font);
0400 void sti_bmove(struct sti_struct *sti, int src_y, int src_x,
0401         int dst_y, int dst_x, int height, int width,
0402         struct sti_cooked_font *font);
0403 
0404 #endif  /* STICORE_H */