Subversion Repositories Kolibri OS

Rev

Rev 876 | Blame | Last modification | View Log | Download | RSS feed

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