Subversion Repositories Kolibri OS

Rev

Rev 813 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "pci.h"
  3. #include "rhd_regs.h"
  4.  
  5. #define IS_R300_3D   0
  6. #define IS_R500_3D   1
  7.  
  8. #define R300_PIO     0
  9.  
  10. enum RHD_CHIPSETS {
  11.     RHD_UNKNOWN = 0,
  12.     RHD_R300,
  13.     RHD_R350,
  14.     RHD_RV350,
  15.     RHD_RV370,
  16.     RHD_RV380,
  17.     /* R500 */
  18.     RHD_RV505,
  19.     RHD_RV515,
  20.     RHD_RV516,
  21.     RHD_R520,
  22.     RHD_RV530,
  23.     RHD_RV535,
  24.     RHD_RV550,
  25.     RHD_RV560,
  26.     RHD_RV570,
  27.     RHD_R580,
  28.     /* R500 Mobility */
  29.     RHD_M52,
  30.     RHD_M54,
  31.     RHD_M56,
  32.     RHD_M58,
  33.     RHD_M62,
  34.     RHD_M64,
  35.     RHD_M66,
  36.     RHD_M68,
  37.     RHD_M71,
  38.     /* R500 integrated */
  39.     RHD_RS600,
  40.     RHD_RS690,
  41.     RHD_RS740,
  42.     /* R600 */
  43.     RHD_R600,
  44.     RHD_RV610,
  45.     RHD_RV630,
  46.     /* R600 Mobility */
  47.     RHD_M72,
  48.     RHD_M74,
  49.     RHD_M76,
  50.     /* RV670 came into existence after RV6x0 and M7x */
  51.     RHD_RV670,
  52.     RHD_R680,
  53.     RHD_RV620,
  54.     RHD_M82,
  55.     RHD_RV635,
  56.     RHD_M86,
  57.     RHD_RS780,
  58.     RHD_CHIP_END
  59. };
  60.  
  61. enum RHD_FAMILIES {
  62.     RHD_FAMILY_UNKNOWN = 0,
  63.  
  64.     RHD_FAMILY_RADEON,
  65.  
  66.     RHD_FAMILY_RV100,
  67.     RHD_FAMILY_RS100,    /* U1 (IGP320M) or A3 (IGP320)*/
  68.     RHD_FAMILY_RV200,
  69.     RHD_FAMILY_RS200,    /* U2 (IGP330M/340M/350M) or A4 (IGP330/340/345/350), RS250 (IGP 7000) */
  70.     RHD_FAMILY_R200,
  71.     RHD_FAMILY_RV250,
  72.     RHD_FAMILY_RS300,    /* RS300/RS350 */
  73.     RHD_FAMILY_RV280,
  74.  
  75.     RHD_FAMILY_R300,
  76.     RHD_FAMILY_R350,
  77.     RHD_FAMILY_RV350,
  78.     RHD_FAMILY_RV380,    /* RV370/RV380/M22/M24 */
  79.     RHD_FAMILY_R420,     /* R420/R423/M18 */
  80.     RHD_FAMILY_RV410,    /* RV410, M26 */
  81.     RHD_FAMILY_RS400,    /* xpress 200, 200m (RS400) Intel */
  82.     RHD_FAMILY_RS480,    /* xpress 200, 200m (RS410/480/482/485) AMD */
  83.  
  84.     RHD_FAMILY_RV515,
  85.     RHD_FAMILY_R520,
  86.     RHD_FAMILY_RV530,
  87.     RHD_FAMILY_RV560,
  88.     RHD_FAMILY_RV570,
  89.     RHD_FAMILY_R580,
  90.     RHD_FAMILY_RS690,
  91.     RHD_FAMILY_R600,
  92.     RHD_FAMILY_RV610,
  93.     RHD_FAMILY_RV630,
  94.     RHD_FAMILY_RV670,
  95.     RHD_FAMILY_RV620,
  96.     RHD_FAMILY_RV635,
  97.     RHD_FAMILY_RS780
  98. };
  99.  
  100. #define RHD_FB_BAR         0
  101. #define RHD_MMIO_BAR       2
  102.  
  103. #define RHD_MEM_GART       1
  104. #define RHD_MEM_FB         2
  105.  
  106. typedef struct RHDRec
  107. {
  108.   CARD32            MMIOBase;
  109.   CARD32            MMIOMapSize;
  110.   CARD32            videoRam;
  111.  
  112.   CARD32            FbBase;            /* map base of fb   */
  113.   CARD32            PhisBase;
  114.   CARD32            FbIntAddress;      /* card internal address of FB */
  115.   CARD32            FbMapSize;
  116.  
  117.   CARD32            FbFreeStart;
  118.   CARD32            FbFreeSize;
  119.  
  120.   /* visible part of the framebuffer */
  121.   unsigned int      FbScanoutStart;
  122.   unsigned int      FbScanoutSize;
  123.  
  124.   enum RHD_CHIPSETS ChipSet;
  125.   enum RHD_FAMILIES ChipFamily;
  126.  
  127.   char              *ChipName;
  128.  
  129.   Bool              IsIGP;
  130.  
  131.   CARD32            bus;
  132.   CARD32            devfn;
  133.  
  134.   PCITAG            PciTag;
  135.   CARD16            PciDeviceID;
  136.  
  137.   CARD16            subvendor_id;
  138.   CARD16            subdevice_id;
  139.  
  140.   CARD32            memBase[6];
  141.   CARD32            ioBase[6];
  142.   CARD32            memtype[6];
  143.   CARD32            memsize[6];
  144.  
  145.   struct mem_block  *fb_heap;
  146.   struct mem_block  *gart_heap;
  147.  
  148.   CARD32            displayWidth;
  149.   CARD32            displayHeight;
  150.  
  151.   CARD32            __xmin;
  152.   CARD32            __ymin;
  153.   CARD32            __xmax;
  154.   CARD32            __ymax;
  155.  
  156.   CARD32            gui_control;
  157.   CARD32            dst_pitch_offset;
  158.   CARD32            surface_cntl;
  159.  
  160.   u32               *ring_base;
  161.   u32               ring_rp;
  162.   u32               ring_wp;
  163.  
  164.   int               num_gb_pipes;
  165.   Bool              has_tcl;
  166. }RHD_t, *RHDPtr;
  167.  
  168. extern RHD_t rhd;
  169.  
  170. typedef struct
  171. {
  172.   int xmin;
  173.   int ymin;
  174.   int xmax;
  175.   int ymax;
  176. }clip_t, *PTRclip;
  177.  
  178.  
  179. typedef struct
  180. {
  181.   u32_t width;
  182.   u32_t height;
  183.   u32_t format;
  184.   u32_t pitch;
  185.   u32_t offset;
  186.   u32_t pitch_offset;
  187.   u32_t *raw;
  188. }pixmap_t;
  189.  
  190.  
  191. typedef struct {
  192.     int                 token;          /* id of the token */
  193.     const char *        name;           /* token name */
  194. } SymTabRec, *SymTabPtr;
  195.  
  196.  
  197.  
  198. extern inline void
  199. OUTREG8(CARD16 offset, u8 value)
  200. {
  201.   *(volatile CARD8 *)((CARD8 *)(rhd.MMIOBase + offset)) = value;
  202. }
  203.  
  204.  
  205. extern inline CARD32 INREG(CARD16 offset)
  206. {
  207.   return *(volatile CARD32 *)((CARD8*)(rhd.MMIOBase + offset));
  208. }
  209.  
  210. //#define INREG(offset) *(volatile CARD32 *)((CARD8*)(rhd.MMIOBase + (offset)))
  211.  
  212. extern inline void
  213. OUTREG(CARD16 offset, CARD32 value)
  214. {
  215.   *(volatile CARD32 *)((CARD8 *)(rhd.MMIOBase + offset)) = value;
  216. }
  217.  
  218. extern inline CARD32 _RHDRegRead(RHDPtr rhdPtr, CARD16 offset)
  219. {
  220.   return *(volatile CARD32 *)((CARD8*)(rhdPtr->MMIOBase + offset));
  221. }
  222.  
  223. extern inline void
  224. MASKREG(CARD16 offset, CARD32 value, CARD32 mask)
  225. {
  226.   CARD32 tmp;
  227.  
  228.   tmp = INREG(offset);
  229.   tmp &= ~mask;
  230.   tmp |= (value & mask);
  231.   OUTREG(offset, tmp);
  232. };
  233.  
  234. extern inline void
  235. _RHDRegWrite(RHDPtr rhdPtr, CARD16 offset, CARD32 value)
  236. {
  237.   *(volatile CARD32 *)((CARD8 *)(rhdPtr->MMIOBase + offset)) = value;
  238. }
  239.  
  240. extern inline void
  241. _RHDRegMask(RHDPtr rhdPtr, CARD16 offset, CARD32 value, CARD32 mask)
  242. {
  243.   CARD32 tmp;
  244.  
  245.   tmp = _RHDRegRead(rhdPtr, offset);
  246.   tmp &= ~mask;
  247.   tmp |= (value & mask);
  248.   _RHDRegWrite(rhdPtr, offset, tmp);
  249. };
  250.  
  251. enum RHD_FAMILIES RHDFamily(enum RHD_CHIPSETS chipset);
  252.  
  253. #define RHDRegRead(ptr, offset) _RHDRegRead((ptr)->rhdPtr, (offset))
  254. #define RHDRegWrite(ptr, offset, value) _RHDRegWrite((ptr)->rhdPtr, (offset), (value))
  255. #define RHDRegMask(ptr, offset, value, mask) _RHDRegMask((ptr)->rhdPtr, (offset), (value), (mask))
  256.  
  257.  
  258. RHDPtr FindPciDevice();
  259.  
  260. Bool RHDPreInit();
  261. int rhdInitHeap(RHDPtr rhdPtr);
  262.  
  263. #define RHDFUNC(ptr)
  264.  
  265. #define DBG(x) x
  266. //  #define DBG(x)
  267.  
  268. #pragma pack (push,1)
  269. typedef struct s_cursor
  270. {
  271.    u32   magic;                           // 'CURS'
  272.    void  (*destroy)(struct s_cursor*);    // destructor
  273.    u32   fd;                              // next object in list
  274.    u32   bk;                              // prev object in list
  275.    u32   pid;                             // owner id
  276.  
  277.    void *base;                            // allocated memory
  278.    u32   hot_x;                           // hotspot coords
  279.    u32   hot_y;
  280. }cursor_t;
  281. #pragma pack (pop)
  282.  
  283. #define LOAD_FROM_FILE   0
  284. #define LOAD_FROM_MEM    1
  285. #define LOAD_INDIRECT    2
  286.  
  287. cursor_t *create_cursor(u32 pid, void *src, u32 flags);
  288. void __stdcall copy_cursor(void *img, void *src);
  289. void destroy_cursor(cursor_t *cursor);
  290. void __destroy_cursor(cursor_t *cursor);                // wrap
  291.  
  292. void __stdcall r500_SelectCursor(cursor_t *cursor);
  293. void __stdcall r500_SetCursor(cursor_t *cursor, int x, int y);
  294. void __stdcall r500_CursorRestore(int x, int y);
  295.  
  296. void  R5xx2DInit();
  297.  
  298.  
  299. typedef struct {
  300.     u32_t x ;
  301.     u32_t y ;
  302. } xPointFixed;
  303.  
  304. typedef u32_t   xFixed_16_16;
  305.  
  306. typedef xFixed_16_16  xFixed;
  307.  
  308. #define XFIXED_BITS 16
  309.  
  310. #define xFixedToInt(f)  (int) ((f) >> XFIXED_BITS)
  311. #define IntToxFixed(i)  ((xFixed) (i) << XFIXED_BITS)
  312.  
  313. #define xFixedToFloat(f) (((float) (f)) / 65536)
  314.  
  315. #define PICT_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) |  \
  316.                                          ((type) << 16) | \
  317.                                          ((a) << 12) | \
  318.                                          ((r) << 8) | \
  319.                                          ((g) << 4) | \
  320.                                          ((b)))
  321.  
  322. #define PICT_FORMAT_A(f)  (((f) >> 12) & 0x0f)
  323. #define PICT_FORMAT_RGB(f)  (((f)      ) & 0xfff)
  324.  
  325. #define PICT_TYPE_OTHER 0
  326. #define PICT_TYPE_A     1
  327. #define PICT_TYPE_ARGB  2
  328. #define PICT_TYPE_ABGR  3
  329. #define PICT_TYPE_COLOR 4
  330. #define PICT_TYPE_GRAY  5
  331.  
  332. typedef enum _PictFormatShort {
  333.    PICT_a8r8g8b8 =      PICT_FORMAT(32,PICT_TYPE_ARGB,8,8,8,8),
  334.    PICT_x8r8g8b8 =      PICT_FORMAT(32,PICT_TYPE_ARGB,0,8,8,8),
  335.    PICT_a8b8g8r8 =      PICT_FORMAT(32,PICT_TYPE_ABGR,8,8,8,8),
  336.    PICT_x8b8g8r8 =      PICT_FORMAT(32,PICT_TYPE_ABGR,0,8,8,8),
  337.  
  338. /* 24bpp formats */
  339.    PICT_r8g8b8 =        PICT_FORMAT(24,PICT_TYPE_ARGB,0,8,8,8),
  340.    PICT_b8g8r8 =        PICT_FORMAT(24,PICT_TYPE_ABGR,0,8,8,8),
  341.  
  342. /* 16bpp formats */
  343.    PICT_r5g6b5 =        PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,6,5),
  344.    PICT_b5g6r5 =        PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,6,5),
  345.  
  346.    PICT_a1r5g5b5 =      PICT_FORMAT(16,PICT_TYPE_ARGB,1,5,5,5),
  347.    PICT_x1r5g5b5 =      PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,5,5),
  348.    PICT_a1b5g5r5 =      PICT_FORMAT(16,PICT_TYPE_ABGR,1,5,5,5),
  349.    PICT_x1b5g5r5 =      PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,5,5),
  350.    PICT_a4r4g4b4 =      PICT_FORMAT(16,PICT_TYPE_ARGB,4,4,4,4),
  351.    PICT_x4r4g4b4 =      PICT_FORMAT(16,PICT_TYPE_ARGB,0,4,4,4),
  352.    PICT_a4b4g4r4 =      PICT_FORMAT(16,PICT_TYPE_ABGR,4,4,4,4),
  353.    PICT_x4b4g4r4 =      PICT_FORMAT(16,PICT_TYPE_ABGR,0,4,4,4),
  354.  
  355. /* 8bpp formats */
  356.    PICT_a8 =            PICT_FORMAT(8,PICT_TYPE_A,8,0,0,0),
  357.    PICT_r3g3b2 =        PICT_FORMAT(8,PICT_TYPE_ARGB,0,3,3,2),
  358.    PICT_b2g3r3 =        PICT_FORMAT(8,PICT_TYPE_ABGR,0,3,3,2),
  359.    PICT_a2r2g2b2 =      PICT_FORMAT(8,PICT_TYPE_ARGB,2,2,2,2),
  360.    PICT_a2b2g2r2 =      PICT_FORMAT(8,PICT_TYPE_ABGR,2,2,2,2),
  361.  
  362.    PICT_c8 =            PICT_FORMAT(8,PICT_TYPE_COLOR,0,0,0,0),
  363.    PICT_g8 =            PICT_FORMAT(8,PICT_TYPE_GRAY,0,0,0,0),
  364.  
  365.    PICT_x4a4 =          PICT_FORMAT(8,PICT_TYPE_A,4,0,0,0),
  366.  
  367.    PICT_x4c4 =          PICT_FORMAT(8,PICT_TYPE_COLOR,0,0,0,0),
  368.    PICT_x4g4 =          PICT_FORMAT(8,PICT_TYPE_GRAY,0,0,0,0),
  369.  
  370. /* 4bpp formats */
  371.    PICT_a4 =            PICT_FORMAT(4,PICT_TYPE_A,4,0,0,0),
  372.    PICT_r1g2b1 =        PICT_FORMAT(4,PICT_TYPE_ARGB,0,1,2,1),
  373.    PICT_b1g2r1 =        PICT_FORMAT(4,PICT_TYPE_ABGR,0,1,2,1),
  374.    PICT_a1r1g1b1 =      PICT_FORMAT(4,PICT_TYPE_ARGB,1,1,1,1),
  375.    PICT_a1b1g1r1 =      PICT_FORMAT(4,PICT_TYPE_ABGR,1,1,1,1),
  376.  
  377.    PICT_c4 =            PICT_FORMAT(4,PICT_TYPE_COLOR,0,0,0,0),
  378.    PICT_g4 =            PICT_FORMAT(4,PICT_TYPE_GRAY,0,0,0,0),
  379.  
  380. /* 1bpp formats */
  381.    PICT_a1 =            PICT_FORMAT(1,PICT_TYPE_A,1,0,0,0),
  382.  
  383.    PICT_g1 =            PICT_FORMAT(1,PICT_TYPE_GRAY,0,0,0,0),
  384. } PictFormatShort;
  385.  
  386.